public static void main(String[] args) {
// TODO Auto-generated method stub
// 输入日期某年某月某日,判断是这一年的第几天
Scanner scan = new Scanner(System.in);
System.out.print("请输入年:");
int year = scan.nextInt();
System.out.print("请输入月:");
int month = scan.nextInt();
System.out.print("请输入日:");
int day = scan.nextInt();
int total = 0;
int[] months = { 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31 }; // 平年
if (year % 400 == 0 || (year % 100 != 0 && year % 4 == 0)) { // 闰年
months[1] = 29; // 二月
}
for (int i = 0; i < month - 1; i++) {
total = total + months[i];
}
total = total + day;
System.out.println(year + "年"+ month + "月" + day + "日是" + year + "年的第" + total + "天");
}
Java编程题(笔试题):输入日期某年某月某日,判断是这一年的第几天
最新推荐文章于 2022-12-25 22:11:09 发布