gpt4 book ai didi

java - 闰年代码-如何在m​​ain方法中调用?

转载 作者:行者123 更新时间:2023-11-30 03:01:17 24 4
gpt4 key购买 nike

这是我用来确定一年是否是闰年的代码:

public class leap_year {
public static void main(String args[])
{
isLeapYear(2009)
}

public static boolean isLeapYear(int year) {
if (year % 4 != 0) {
return false;
} else if (year % 400 == 0) {
return true;
} else if (year % 100 == 0) {
return false;
} else {
return true;
}
}
}

但是当我运行代码时什么也没有显示。我究竟做错了什么?

最佳答案

没有打印任何内容,因为您还没有订购!使用 System.out.println(...) 将输出打印到控制台。

您的代码应如下所示:

boolean bool = isLeapYear(2009);
System.out.println(bool);

或者不使用任何变量直接打印出来:

System.out.println(isLeapYear(2009));

关于java - 闰年代码-如何在m​​ain方法中调用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35873800/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com