Name: skT88420 Date: 07/08/99
When running the following piece of code I got the
message saying
1100 is a leap year
1300 is a leap year
1400 is a leap year
1500 is a leap year
According to the rules defined for leap year the above years are
NOT leap years.
The full leap year rules
The full rules for calculating whether a year is a leap year or not are -
If the number of the year can be divided by 400 without leaving any remainder; it is a leap year
otherwise
If the number of the year can be divided by 100 without leaving any remainder; it is not a leap year
otherwise
If the number of the year can be divided by four without leaving any remainder; it is a leap year
otherwise
It is not a leap year
1.Please save the following piece of program in a file called DateTest.java
and compile with Sun JDK1.2 java compiler and execute using the java interpreter.
2.The SOURCE code
import java.util.*;
public class DateTest{
public static void main(String av[]){
GregorianCalendar c = new GregorianCalendar();
String leap = (c.isLeapYear(Integer.parseInt(av[0])))?"":" NOT";
System.out.println(av[0]+ " is" + leap + " a leap year" );
}
}
3.The output of the above program
I:\Developers\giri>java DateTest 1100
1100 is a leap year
I:\Developers\giri>java DateTest 1300
1300 is a leap year
I:\Developers\giri>java DateTest 1400
1400 is a leap year
I:\Developers\giri>java DateTest 1500
1500 is a leap year
4.No trace information
5.Output of java -version and java -fullversion
I:\Developers\giri>java -version
java version "1.2"
Classic VM (build JDK-1.2-V, native threads)
I:\Developers\giri>java -fullversion
java full version "JDK-1.2-V"
(Review ID: 85356)
======================================================================