我正在关注"Java的艺术与科学"一书,它展示了如何计算闰年.本书使用ACM Java Task Force的库.
这是书籍使用的代码:
import acm.program.*;
public class LeapYear extends ConsoleProgram {
public void run()
{
println("This program calculates leap year.");
int year = readInt("Enter the year: ");
boolean isLeapYear = ((year % 4 == 0) && (year % 100 != 0) || (year % 400 == 0));
if (isLeapYear)
{
println(year + " is a leap year.");
} else
println(year + " is not a leap year.");
}
}
Run Code Online (Sandbox Code Playgroud)
现在,这就是我计算闰年的方法.
import acm.program.*;
public class LeapYear extends ConsoleProgram { …Run Code Online (Sandbox Code Playgroud)