Java judges leap year and average year and outputs the number of days of a month
•
Java
import java.util.Scanner;
public class Test27 {
public static void main(String[] args) {
// 在这里编写其他代码
}
}
Scanner sc=new Scanner(system.in);
System.out.println("请输入年份(注: 必须大于 1990 年):");
int year=sc.nextInt();
System.out.println("请输入月份:");
int month=sc.nextInt();
boolean isRen;
if((year%4==0&&year%100!=0)||(year%400==0)) {
System.out.println(year+"闰年");
isRen=true;
} else {
System.out.println(year+"平年");
isRen=false;
}
int day=0;
switch(month) {
case 1:
case 3:
case 5:
case 7:
case 8:
case 10:
case 12:
day=31;
break;
case 4:
case 6:
case 9:
case 11:
day=30;
break;
default:
if(isRen) {
day=29;
} else {
day=28;
}
break;
}
System.out.println(year+"年"+month+"月共有"+day+"天");
请输入年份(注: 必须大于 1990 年): 2014 请输入月份: 2 2014平年 2014年2月共有28天
请输入年份(注: 必须大于 1990 年): 2000 请输入月份: 2 2000闰年 2000年2月共有29天
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
