题目描述
请从标注输入流(控制台)中获取一个自然数year表示年份。如果year是一个闰年,通过System.out.ptinyln语句输出is a leap year到标准输出流(控制台)。否则,通过system.out.println语句输出not a leap year到标准输出流(控制台)。
思路
入门题。如题目描述实现即可
Java代码
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
// write your code here
// read data from console
Scanner scanner = new Scanner(System.in);
int year = scanner.nextInt();
if (year > 0 && year % 4 == 0) {
if (year % 100 != 0 || year % 400 == 0) {
System.out.println("is a leap year");
return;
}
}
// output the answer to the console according to the
// requirements of the question
System.out.println("not a leap year");
}
}