I'm trying to learn Java. When I enter 1800 which is not a leap year, it says "Leap year" but if I enter 2011 which is not a leap year it says "not leap year".
anyone that can help? I'm new to Java so I'm learning all this. The problem I'm trying to solve is noted below.
A year is a leap year if it is divisible by 4. However, if the year is divisible by 100, then it is a leap year only when it is also divisible by 400.
import java.util.Scanner;
public class leapyears {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.println("Enter a year!");
int year = Integer.valueOf(scanner.nextLine());
if (year % 4 == 0) {
System.out.println("Leap year!");
if (year % 100 != 0 && year % 400 == 0) {
System.out.println("Leap year!");
}
} else {
System.out.println("Not leap year!");
}
}
}