import java.util.Scanner;
class TotalDays
{
public static void main(String[] args)
{
Scanner s = new Scanner(System.in);
System.out.print("请您输入一个年份:");
int year = s.nextInt();
System.out.print("请您输入一个月份:");
int month = s.nextInt();
System.out.println("您输入的日期共有" + totaldays(year,month) + "天");
}
public static boolean runNian(int a)//判断闰年
{
if (a % 400 == 0 || (a % 4 == 0 && a % 100 != 0))
{
return true;
}
return false;
}
public static int nian(int a)//闰年一年天数
{
if (runNian(a))
{
return 366;
}
else
return 365;
}
public static int monthDay(int a)//那一年某月的天数
{
if (a == 1 || a == 3 || a == 5 || a == 7 || a == 8 || a == 10 || a == 12)
{
return 31;
}
else if (a == 4 || a == 6 || a == 9 || a == 11)
{
return 30;
}
else
if (runNian(a))
{
return 29;
}
else
return 28;
}
public static int totaldays(int a , int b)//某年某月的天数
{
int totalyear = 0;
int totalmonth = 0;
int totaldays = 0;
for (int c = 1980; c < a ; c++ )
{
totalyear = totalyear + nian(a);
}
for (int d = 1; d < b ; d++ )
{
totalmonth = totalmonth + monthDay(b);
}
totaldays = totalyear + totalmonth;
return totaldays;
}
}
ziom
qq_随心_57
相关分类