QuestionAsk Questions?

View Answers

October 30, 2008 at 4:08 PM

hello,

try the follwing code hope this will sovle u r problem.

public class LeapYear {

public static void main (String[] args) {

// The year to check for leapiness.

int year = 1998;

// Check for a 2 digit year and adjust the year

// using a windowing technique. If the date has

// more than 2 digits we'll assume it is a complete

// year.

if (year < 100) {

// If the year is greater than 40 assume it

// is from 1900's. If the year is less than

// 40 assume it is from 2000's.

if (year > 40) {

year = year + 1900;

}

else {

year = year + 2000;

}

}

// Is theYear Divisible by 4?

if (year % 4 == 0) {

// Is theYear Divisible by 4 but not 100?

if (year % 100 != 0) {

System.out.println(year + " is a Leap year.");

}

// Is theYear Divisible by 4 and 100 and 400?

else if (year % 400 == 0) {

System.out.println(year + " is a Leap year.");

}

// It is Divisible by 4 and 100 but not 400!

else {

System.out.println(year + " is not a Leap year.");

}

}

// It is not divisible by 4.

else {

System.out.println(year + " is not a Leap year.");

}

}

}

October 30, 2008 at 4:35 PM

Hi friend,

import java.io.*;

import java.text.*;

public class LeapYearDemo {

public static void main (String[] args) throws IOException {

int theYear;

BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the year: ");

theYear = Integer.parseInt(buff.readLine());

if (theYear < 100) {

if (theYear > 40) {

theYear = theYear + 1900;

}

else {

theYear = theYear + 2000;

}

}

// Is theYear Divisible by 4?

if (theYear % 4 == 0) {

// Is theYear Divisible by 4 but not 100?

if (theYear % 100 != 0) {

System.out.println(theYear + " is a leap year.");

}

// Is theYear Divisible by 4 and 100 and 400?

else if (theYear % 400 == 0) {

System.out.println(theYear + " is a leap year.");

}

// It is Divisible by 4 and 100 but not 400!

else {

System.out.println(theYear + " is not a leap year.");

}

}

else {

System.out.println(theYear + " is not a leap year.");

}

}

}

------------------------------------------

Visit for more information.

http://www.roseindia.net/java/

Thanks.

import java.io.*;

import java.text.*;

public class LeapYearDemo {

public static void main (String[] args) throws IOException {

int theYear;

BufferedReader buff = new BufferedReader(new InputStreamReader(System.in));

System.out.print("Enter the year: ");

theYear = Integer.parseInt(buff.readLine());

if (theYear < 100) {

if (theYear > 40) {

theYear = theYear + 1900;

}

else {

theYear = theYear + 2000;

}

}

// Is theYear Divisible by 4?

if (theYear % 4 == 0) {

// Is theYear Divisible by 4 but not 100?

if (theYear % 100 != 0) {

System.out.println(theYear + " is a leap year.");

}

// Is theYear Divisible by 4 and 100 and 400?

else if (theYear % 400 == 0) {

System.out.println(theYear + " is a leap year.");

}

// It is Divisible by 4 and 100 but not 400!

else {

System.out.println(theYear + " is not a leap year.");

}

}

else {

System.out.println(theYear + " is not a leap year.");

}

}

}

------------------------------------------

Visit for more information.

http://www.roseindia.net/java/

Thanks.

Related Tutorials/Questions & Answers: