实现统计今天是该月的有多少天关键算法。从键盘上输入一个年份值和一个月份值,输出该月的天数。
说明:一年有 12 个月,大
月的天数是 31,小月的天数是 30。2 月的天数比较特殊,遇到闰年是 29 天,否则为 28 天。
例如,输入 2011、3,则输出 31 天。
注意:使用分支结构语句实现。
public class week1 {
public static void main(String[] args) {
int[] intArray={31,28,31,30,31,30,31,31,30,31,30,31};//十二月份
Scanner input = new Scanner(System.in);
System.out.println("请输入某年某月:");
System.out.print("年:");
int year= input.nextInt();
System.out.print("月:");
int mm= input.nextInt();
//每过四年就有一次闰年
//如果是闰年。
if((year % 4 == 0 && year % 100 != 0)||(year % 400 == 0)){
intArray[1] = 29;//闰年天数加1
}
System.out.println(year+"年的"+mm+"月有"+intArray[mm-1]+"天");
}
}