import java.util.*; public class Test{ public int getCurrDay(int year,int month,int day){ int daySum=0; for(int i=1;i<month;i++){ daySum+=getDays(year,i); } daySum+=day; return daySum; } //取得该月有几天 private int getDays(int year,int month){ switch(month) { case 1: case 3: case 5: case 7: case 8: case 10: case 12: return 31; case 4: case 6: case 9: case 11: return 30; case 2: if(isRunNian(year)){ return 29; }else{ return 28; } } return 0; } //判断是不是闰年 private boolean isRunNian(int year){ if(year%400==0||(year%4==0&&year%100!=0)) return true; else return false; } public static void main(String args[]){ Scanner scan = new Scanner(System.in); System.out.println("please input year: "); int year = scan.nextInt(); System.out.println("please input month: "); int month = scan.nextInt(); System.out.println("please input day: "); int day = scan.nextInt(); System.out.println("the day you input is the "+new Test().getCurrDay(year,month,day)+"day of the year"); } }