【题目要求】
输入某年某月某日,判断这一天是这一年的第几天?
【代码】
import java.util.Scanner;
public class Ta {
public static void main(String[] args){
Scanner str = new Scanner(System.in);
System.out.println("Please input the year:");
int year=str.nextInt();
System.out.println("Please input the month:");
int month=str.nextInt();
System.out.println("Please input the dath:");
int dath=str.nextInt();
int days=dath;
int[] l=new int[]{0,31,0,31,30,31,30,31,31,30,31,30,31};
if((year%4==0&&year%100!=0)||(year%400==0)){
l[2]=29;
}else{
l[2]=28;
}
for(int i=1;i<month;i++){
days+=l[i];
}
System.out.println(days);
}
}
【输出结果】