Write a program to judge whether a given year is a leap
year. The rules for judging a leap year are as follows:
(1) If a year is divisible by 4 but not divisible by 100, it is a leap year.
(2) If a certain year is divisible by 400, it is also a leap year.
(Small exercises for beginners to learn Java by yourself)
import java.util.Scanner;
public class TestDemo{
public static void main(String[] args){
Scanner sc=new Scanner(System.in);//与键盘建立连接
System.out.println("请输入年份:");
int year=sc.nextInt();
int remainder1=year%4;
int remainder2=year%100;
int remainder3=year%400;
if((remainder1 ==0 && remainder2 !=0) || remainder3==0){
System.out.println(year+"是闰年");
}else{
System.out.println(year+"不是闰年");
}
}
}
The results of the operation are as follows: