我试图让方法LeapYear返回它是否或不是LeapYear(返回任何它是否实际上是语句)。基本上,我是新来的编码,我不知道如何返回一个字符串值,而不是一个int或一个双。任何人都可以帮助我吗?闰年方法
public static int LeapYear(int y) {
int theYear;
theYear = y;
if (theYear < 100) {
if (theYear > 40) {
theYear = theYear + 1900;
} else {
theYear = theYear + 2000;
}
}
if (theYear % 4 == 0) {
if (theYear % 100 != 0) {
System.out.println("IT IS A LEAP YEAR");
} else if (theYear % 400 == 0) {
System.out.println("IT IS A LEAP YEAR");
} else {
System.out.println("IT IS NOT A LEAP YEAR");
}
} else {
System.out.println("IT IS NOT A LEAP YEAR");
}
}
帮助自己做读者的工作变得更轻松:去掉无关的代码(即因子和绝对值方法与您的问题无关:不要将它们包含在您的帖子中)。 – assylias
当你关注闰年时,为什么张贴阶乘代码? –