首页 > 代码库 > java基础练习 13

java基础练习 13

import java.util.Scanner;
public class Thirtheen {
/*输入某年某月某日,判断这一天是这一年的第几天?*/
public static void main(String[] args){
Scanner input=new Scanner(System.in);
int sum,i;
System.out.print("请输入年份:");
int a=input.nextInt();
System.out.print("\n");
System.out.print("请输入月份:");
int b=input.nextInt();
System.out.print("\n");
System.out.print("请输入日:");
int c=input.nextInt();
System.out.print("\n");

if(a%4==0&&a%100!=0&&b>1)
sum=29;
else if(b>1)
sum=28;
else
sum=0;
for(i=1;i<b;i++){
if(i==2)
continue;
switch(i){
case 1: case 3: case 5: case 7: case 8: case 10: case 12:
sum=sum+31;
case 4: case 6: case 9: case 11:
sum=sum+30;

}
}
sum=sum+c;
System.out.println("到"+a+"年"+b+"月"+c+"日"+","+a+"年过去了"+sum+"天");

}

}

java基础练习 13