package syj;
import java.util.Scanner;
public class runyear {
public static void main(String[] args) {
System.out.print("输入年份:");
Scanner sc = new Scanner(System.in);
int year = sc.nextInt();
//设置布尔型变量存满足闰年的条件
if(year<=1900||year>=2010)
{System.out.println(year + "您输入的年份不在范围内!");}
else {};
boolean isRn = (year % 4 == 0) && (year % 100 != 0)||(year%400==0);
//用if-else结构判断输入年份是否为闰年
if (isRn) {
System.out.println(year + "年是闰年");
} else {
System.out.println(year + "年是平年");
}
System.out.print("输入月份:");
int month = sc.nextInt();
//多重if结构判断输入月份的天数
if (month==1||month==3||month==5||month==7||month==8||
month==10||month==12)
{
System.out.println(year + "年" + month + "月的天数是31");
} else if ((month==2) && isRn) {
System.out.println(year + "年" + "2" + "月的天数是29");
} else if ((month==2) && !isRn) {
System.out.println(year + "年" + "2" + "月的天数是28");
} else if (month==4||month==6||month==9||month==11) {
System.out.println(year + "年" + month + "月的天数是30");
} else {
System.out.println("输入的月份不正确");
}
}
}
评论4