Leap Year
Completed
Read a year and print true if it is a leap year: divisible by 4, but century years must be divisible by 400.
Input
One integer.
Output
true or false
Example
Input
2024
Output
true
Editor
Java
Hints
&& means and, || means or.
Solution explanation
A boolean expression can be stored in a variable and printed directly.
Show solution
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int y = sc.nextInt();
boolean leap = (y % 4 == 0 && y % 100 != 0) || y % 400 == 0;
System.out.println(leap);
}
}