输入某年某月某日,判断这一天是这一年的第几天?
package com.gyy.exercise;
import java.util.Scanner;
public class exercise14 {
public static void main(String[] args) {
int year,month,day,sumDay=0;
Scanner console =new Scanner(System.in);
year = console.nextInt();
month = console.nextInt();
day = console.nextInt();
int[] months = new int[]{31,28,31,30,31,30,31,31,30,31,30,31};
if((year % 4 == 0 && year % 100 != 0) || (year % 400 == 0))
months[1] = 29;
for(int i =0; i < month-1; i++)
{
sumDay += months[i];
}
sumDay += day;
System.out.println("这一天是这年的第" + sumDay + "天");
}
}
1999 5 19
这一天是这年的第139天
Process finished with exit code 0