import java.util.Scanner;
public class Year {
/*
* date1方法switch求这是当年第几天
*/
private static int date1(int year,int moth,int day) {
//定义变量存放总天数sum
int sum=0;
switch(moth){
case 12:
sum+=30;
case 11:
sum+=31;
case 10:
sum+=30;
case 9:
sum+=31;
case 8:
sum+=31;
case 7:
sum+=30;
case 6:
sum+=31;
case 5:
sum+=30;
case 4:
sum+=31;
case 3:
if((year%4==0&&year%100!=0)||year%400==0){
sum+=29;
}else{
sum+=28;
}
case 2:
sum+=31;
case 1:
sum+=day;
}
return sum;
}
//main方法入口
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
//定义变量y年m月d日 并提示输入
System.out.println("请输入年(如:2017):");
int y=scan.nextInt();
System.out.println("请输入月份(如:3):");
int m=scan.nextInt();
System.out.println("请输入日期:12");
int d=scan.nextInt();
//调用date1方法并输入结果
System.out.println("这是"+y+"的第"+date1(y,m,d)+"天");
//关闭输入流
scan.close();
}
}
public class Year {
/*
* date1方法switch求这是当年第几天
*/
private static int date1(int year,int moth,int day) {
//定义变量存放总天数sum
int sum=0;
switch(moth){
case 12:
sum+=30;
case 11:
sum+=31;
case 10:
sum+=30;
case 9:
sum+=31;
case 8:
sum+=31;
case 7:
sum+=30;
case 6:
sum+=31;
case 5:
sum+=30;
case 4:
sum+=31;
case 3:
if((year%4==0&&year%100!=0)||year%400==0){
sum+=29;
}else{
sum+=28;
}
case 2:
sum+=31;
case 1:
sum+=day;
}
return sum;
}
//main方法入口
public static void main(String[] args){
Scanner scan=new Scanner(System.in);
//定义变量y年m月d日 并提示输入
System.out.println("请输入年(如:2017):");
int y=scan.nextInt();
System.out.println("请输入月份(如:3):");
int m=scan.nextInt();
System.out.println("请输入日期:12");
int d=scan.nextInt();
//调用date1方法并输入结果
System.out.println("这是"+y+"的第"+date1(y,m,d)+"天");
//关闭输入流
scan.close();
}
}