The source code to get the current year using the get() method of the Calendar class is given below. The given program is compiled and executed successfully.
// Java program to get the current year using
// get() method of Calendar class
import java.util.*;
public class Main {
public static void main(String[] args) {
Calendar cal = Calendar.getInstance();
System.out.println("Current Year: " + cal.get(Calendar.YEAR));
}
}
Output:
Current Year: 2022
Explanation:
In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created the object of the Calendar class and got the current year using the get() method, and printed the result.
Program/Source Code:
The source code to get the current year using the get() method of the Calendar class is given below. The given program is compiled and executed successfully.
Output:
Explanation:
In the above program, we created a class Main that contains a static method main(). The main() method is the entry point for the program, here we created the object of the Calendar class and got the current year using the get() method, and printed the result.