import java.util.Random;
import java.util.Scanner;
public class Demo1 {
public static void main(String[] args) {
//输入某年某月某日,判断这一天是这一年的第几天?
add();
}
public static void add() {
Scanner sc = new Scanner(System.in);//设置一个扫描器
int year =0;
int month =0;
int day =0;
int sum =0;
System.out.println("请输入年份:");
if (sc.hasNext()) { //判断下列语句是否为int类型,真则输出,为假则不输出
year =sc.nextInt(); //扫描输入的下一个标记为int
}
System.out.println("请输入月份:");
if (sc.hasNext()) {
month =sc.nextInt();
}
System.out.println("请输入日期:");
if (sc.hasNext()) {
day =sc.nextInt();
}
switch (month) {
case 1:sum=day;break;
case 2:sum=31+day;break;
case 3:sum=31+28+day;break;
case 4:sum=31+28+31+day;break;
case 5:sum=31+28+31+30+day;break;
case 6:sum=31+28+31+30+31+day;break;
case 7:sum=31+28+31+30+31+30+day;break;
case 8:sum=31+28+31+30+31+30+31+day;break;
case 9:sum=31+28+31+30+31+30+31+31+day;break;
case 10:sum=31+28+31+30+31+30+31+31+30+day;break;
case 11:sum=31+28+31+30+31+30+31+31+30+31+day;break;
case 12:sum=31+28+31+30+31+30+31+31+30+31+30+day;break;
default:
System.out.println("输出错误!!!"); break;
}
if (year%4==0) {
sum++;
}
System.out.println("是这年的第"+sum+"天");
}
}
输入某年某月某日,判断这一天是这一年的第几天?
最新推荐文章于 2024-11-03 11:01:20 发布