Found 34471 Articles for Programming

LocalDateTime getHour() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

88 Views

The hour of the day for a particular LocalDateTime can be obtained using the getHour() method in the LocalDateTime class in Java. This method requires no parameters and it returns the hour of the day which can range from 0 to 23.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The hour is: " + ldt.getHour());    } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The hour is: 15Now let ... Read More

LocalDateTime getYear() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

370 Views

The year for a particular LocalDateTime can be obtained using the getYear() method in the LocalDateTime class in Java. This method requires no parameters and it returns the year which can range from MIN_YEAR to MAX_YEAR.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.parse("2019-02-18T15:28:35");       System.out.println("The LocalDateTime is: " + ldt);       System.out.println("The year is: " + ldt.getYear());    } }OutputThe LocalDateTime is: 2019-02-18T15:28:35 The year is: 2019Now let us understand the above program.First the ... Read More

LocalDateTime equals() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

72 Views

The equality of two LocalDateTime objects can be determined using the equals() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object to be compared. Also it returns true if both the LocalDateTime objects are equal and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       LocalDateTime ldt2 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime ldt1 is: " + ldt1);       System.out.println("The LocalDateTime ldt2 is: " ... Read More

LocalDateTime withNano() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

117 Views

An immutable copy of a LocalDateTime with the nanoseconds altered as required is done using the method withNano() in the LocalDateTime class in Java. This method requires a single parameter i.e. the nanosecond that is to be set in the LocalDateTime and it returns the LocalDateTime with the nanosecond altered as required.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime is: " + ldt1);       LocalDateTime ldt2 = ldt1.withNano(5);       ... Read More

LocalDateTime plusWeeks() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

64 Views

An immutable copy of a LocalDateTime object where some weeks are added to it can be obtained using the plusWeeks() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the number of weeks to be added and it returns the LocalDateTime object with the added weeks.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalDateTime ldt = LocalDateTime.now();       System.out.println("The current LocalDateTime is: " + ldt);       System.out.println("The LocalDateTime with 4 weeks added is: ... Read More

LocalTime minusSeconds() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

51 Views

An immutable copy of a LocalTime object where some seconds are subtracted from it can be obtained using the minusSeconds() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of seconds to be subtracted and it returns the LocalTime object with the subtracted seconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The current LocalTime is: " + lt);       System.out.println("The LocalTime with 5 seconds subtracted is: ... Read More

LocalTime plusHours() method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25

34 Views

An immutable copy of a LocalTime object where some hours are added to it can be obtained using the plusHours() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of hours to be added and it returns the LocalTime object with the added hours.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The current LocalTime is: " + lt);       System.out.println("The LocalTime with 3 hours added is: ... Read More

LocalTime plusNanos() method in Java

Samual Sam
Updated on 30-Jul-2019 22:30:25

57 Views

An immutable copy of a LocalTime object where some nanoseconds are added to it can be obtained using the plusNanos() method in the LocalTime class in Java. This method requires a single parameter i.e. the number of nanoseconds to be added and it returns the LocalTime object with the added nanoseconds.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       LocalTime lt = LocalTime.now();       System.out.println("The current LocalTime is: " + lt);       System.out.println("The LocalTime with 1000 nanoseconds added is: ... Read More

C++ Program to Perform Edge Coloring to the Line Graph of an Input Graph

Nitya Raut
Updated on 30-Jul-2019 22:30:25

248 Views

The line graph of an undirected graph G is another graph L(G) that represents the adjacencies between edges of G. In this program, we Perform Edge Coloring to the Line Graph of an Input Graph.AlgorithmBegin    Take the input of the number of vertices ‘n’ and number of edges ‘e’.    Take the input of ‘n’ vertex pairs for the ‘e’ edges in the graph in ed[][].    Function GenLineGraph():       Construct a line graph in LineEd[][].       To construct line graph, for each edge in the given graph, connect it    to its adjacent edge ... Read More

C++ Program to Perform Graph Coloring on Bipartite Graphs

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:25

347 Views

A bipartite graph is a graph in which if the graph coloring is possible using two colors i.e.; vertices in a set are colored with the same color. In this program we take a bipartite graph as input and outputs colors of each vertex after coloring the vertices.AlgorithmBegin BFS algorithm is used to traverse all the vertices. Take a vertex and colour it yellow. Colour all its neighbour vertices as blue. Colour the next level vertices as yellow and so, until all vertices are coloured. End.Example Code#include using ... Read More

Advertisements