1 import java.util.*; 2 public class work_1 { 3 4 public static void main(String[] args) { 5 System.out.println("请输入年份"); 6 Scanner a=new Scanner(System.in); 7 int year=a.nextInt(); 8 System.out.println("请输入月份"); 9 Scanner b=new Scanner(System.in); 10 int month=b.nextInt(); 11 int sum = 0; 12 int x; 13 if(year%4==0&&year%100!=0||year%400==0) {//判断是否为闰年 14 System.out.println("该年为闰年,有366天"); 15 switch(month) { 16 case 1: 17 sum=0; 18 break; 19 case 2: 20 sum=32; 21 break; 22 case 3: 23 sum=60; 24 break; 25 case 4: 26 sum=91; 27 break; 28 case 5: 29 sum=121; 30 break; 31 case 6: 32 sum=152; 33 break; 34 case 7: 35 sum=182; 36 break; 37 case 8: 38 sum=213; 39 break; 40 case 9: 41 sum=244; 42 break; 43 case 10: 44 sum=274; 45 break; 46 case 11: 47 sum=305; 48 break; 49 case 12: 50 sum=335; 51 break; 52 } 53 }else { 54 System.out.println("该年不为闰年,有365天"); 55 switch(month) { 56 case 1: 57 sum=0; 58 break; 59 case 2: 60 sum=31; 61 break; 62 case 3: 63 sum=59; 64 break; 65 case 4: 66 sum=90; 67 break; 68 case 5: 69 sum=120; 70 break; 71 case 6: 72 sum=151; 73 break; 74 case 7: 75 sum=181; 76 break; 77 case 8: 78 sum=212; 79 break; 80 case 9: 81 sum=243; 82 break; 83 case 10: 84 sum=273; 85 break; 86 case 11: 87 sum=304; 88 break; 89 case 12: 90 sum=334; 91 break; 92 } 93 } 94 System.out.println("请输入日子"); 95 int day=a.nextInt(); 96 x=sum+day; 97 System.out.println("该日子为这一年的第"+x+"天"); 98 } 99 100 }