猿问

各位大佬请问我这代码是哪里逻辑出错了,结果一直不正确!

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;

}

}


慕丝2941512
浏览 1183回答 2
2回答

ziom

monthDay(int a)方法里面在调用runNian()的时候传入的是a,a在这里应该是月份,而runNian()要求传入一个年份

qq_随心_57

感觉这个代码不够明确功能,你是要一年多少天呢,还是要什么呢?没看懂
随时随地看视频慕课网APP

相关分类

Java
我要回答