import java.util.Scanner;
class HelloWorldF
{
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,int b)//那一年某月的天数
{
if (b == 1 || b == 3 || b == 5 || b == 7 || b == 8 || b == 10 || b == 12)
{
return 31;
}
else if (b == 4 || b == 6 || b == 9 || b == 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(a,b);
}
totaldays = totalyear + totalmonth;
return totaldays;
}
}
添加回答
举报
0/150
提交
取消