Here is the program.
Code:
import java.util.*;
import java.io.*;
public class LeapYear{
public static void main(String[] args) throws IOException{
BufferedReader inter = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter year : ");
int y;
try{
y = Integer.parseInt(in.readLine());
if(y < 1900 || y > 2100){
System.out.print("enter year that is less than 2101 and greater than 1899.");
System.exit(0);
}
GregorianCalendar c = new GregorianCalendar();
if(c.isLeapYear(y))
System.out.print("Enter year is leap year.");
else
System.out.print("Enter year is not leap year.");
}
catch(NumberFormatException ne){
System.out.print(ne.getMessage() + " is not a proper number.");
System.out.println("Please proper number.");
System.exit(0);
}
}
}
Bookmarks