I am trying to solve a simple assignment from a course I have enrolled in, but it's not working for some reason.
Assignment says: "A year is a leap year if it is divisible by 4. But if the year is divisible by 100, it is a leap year only when it is also divisible by 400. Create a program that checks whether the given year is a leap year."
When I run the code I get the message: "With input 1604 you should print "The year is a leap year", but you printed "Type a year: The year is not a leap year." "
This is my code:
Scanner reader = new Scanner(System.in);
System.out.print("Type a year: ");
int year = Integer.parseInt(reader.nextLine());
if((year % 4 == 0) && (year % 100 == 0 && year % 400 == 0)) {
System.out.println("The year is a leap year.");
}else {
System.out.println("The year is not a leap year.");
}
}
}