题目:某年某月某日第n天
/*
- 从键盘输入年、月、日,判断这一天是当年的第几天
- 注:判断一年是否是闰年的标准:
- (1)可以被4整除,但不可以被100整除
- (2)
*/
import java.util.Scanner;
public class switchCaseExer5 {
public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
System.out.println("请输入year:");
int year = scan.nextInt();
System.out.println("请输入month:");
int month = scan.nextInt();
System.out.println("请输入day:");
int day = scan.nextInt();
int sumDays = 0;
switch(month) {
case 12:
sumDays += 30;
case 11:
sumDays += 31;
case 10:
sumDays += 30;
case 9:
sumDays += 31;
case 8:
sumDays += 31;
case 7:
sumDays += 30;
case 6:
sumDays += 31;
case 5:
sumDays += 30;
case 4:
sumDays += 31;
case 3:
//判断year是否是闰年
if(( year % 4 == 0 && year %100 != 0 )|| year % 400 == 0) {
sumDays += 29;
}else {
sumDays += 28;
}
case 2:
sumDays += 31;
case 1:
sumDays += day;
}
System.out.println(year+"年"+month+"月"+day+"日 是当年的第"+sumDays+"天");
}
}
输出①:
请输入year:
2019
请输入month:
3
请输入day:
1
2019年3月1日 是当年的第60天
输出②:
请输入year:
2020
请输入month:
3
请输入day:
1
2020年3月1日 是当年的第61天
博客围绕判断某年某月某日是当年第几天的题目展开,需从键盘输入年、月、日信息,还提及判断闰年的标准,即能被4整除但不能被100整除等,使用Java语言结合switch语句来实现该功能。
switch-case结构练习5----某年某月某日第n天&spm=1001.2101.3001.5002&articleId=110496405&d=1&t=3&u=a01bea5434e34ae2bd5fba0992b2495b)
2015

被折叠的 条评论
为什么被折叠?



