All years that are evenly divisible by 400 or are evenly
divisible by four and not evenly divisible by 100 are
leap years. For example, since 1600 is evenly divisible
by 400, the year is was a leap year. Similarly, since
1988 is evenly divisible by four but not by 100, the year
1988 was also a leap year. Using this information write
a Java method that accepts the year as user input,
determines if the year is a leap year, and displays an
appropriate message that tells the user if the entered
year is or is not a leap year.
Note: Use if Control statement
import java.util.Scanner;
public class Main {
public static void main(String[] args){
int Y;
System.out.println("Enter a Year :: ");
Scanner input = new Scanner(System.in);
Y = input.nextInt();
if (((Y % 4 == 0) && (Y % 100!= 0)) || (Y%400 == 0))
System.out.println(Y+" is a leap year");
else
System.out.println(Y+" is not a leap year");
}
}
Comments
Leave a comment