/*
* 用户输入年、月、天数,求该天是这一年的第多少天
*/
package Ch02;
/*import java.util.Calendar;*/
import java.util.Scanner;
public class Demo10 {
public static void main(String[] args) {
// TODO Auto-generated method stub
/*Scanner input = new Scanner(System.in);
System.out.println("请输入年份:");
int y = input.nextInt();
System.out.println("请输入月份:");
int m = input.nextInt();
System.out.println("请输入天数:");
int d = input.nextInt();
Calendar calendar=Calendar.getInstance();
calendar.set(y,m-1,d);
System.out.println("一年中的第"+calendar.get(Calendar.DAY_OF_YEAR)+"天");*/
Scanner input = new Scanner(System.in);
System.out.println("请输入年份:");
int y = input.nextInt();
System.out.println("请输入月份:");
int m = input.nextInt();
System.out.println("请输入天数:");
int d = input.nextInt();
int s = 0;
switch(m){
case 1: s=d; break;
case 2: s=31+d; break;
case 3: s=59+d; break;
case 4: s=90+d; break;
case 5: s=120+d; break;
case 6: s=151+d; break;
case 7: s=181+d; break;
case 8: s=212+d; break;
case 9: s=243+d; break;
case 10: s=273+d; break;
case 11: s=304+d; break;
case 12: s=334+d; break;
}
if(y%4==0 && y%100!=0 || y%400==0){
if(m>2){
s++;
}
}
String str=String.format("你输入的年份为:%d年%d月%d日,是%d年的第%d天",y,m,d,y,s);
System.out.println(str);
}
}