Java Programing laungage

java.util Projects

java.util Project 1

Determining Leap Year or not

Leap Year: Leap Year is the year which is contain an extra day. In the leap year, the February month contains 29 days since normally February month has 28 days. The year which is completely divided by 4 that is the leap year. for find the Leap year we can use the isLeapYear(year) method of the Calendar class.

Previous Home Next

Calendar.isLeapYear(year): This method is used to return a boolean value true, if the year is leap year otherwise it returns the boolean value false. This program checks each and every entries properly.


package r4r;
import java.util.*;
public class leapyeartests {
public static void main(String[] args) throws IOException{
BufferedReader br = new BufferedReader(new InputStreamReader(;
System.out.print("Enter any year : ");
int year;
year = Integer.parseInt(br.readLine()); if(year < 1900 || year > 2100){ System.out.print("Enter a year less than 2101 and greater than 1899."); System.exit(0); }[an error occurred while processing this directive] GregorianCalendar cal = new GregorianCalendar(); if(cal.isLeapYear(year)) System.out.print("It is leap year."); else System.out.print("It is not leap year."); } catch(NumberFormatException ne){ System.out.print(ne.getMessage() + " is not a right entry."); System.out.println("Enter a 4-digit number only."); System.exit(0); } } }
Previous Home Next