小编spo*_*Top的帖子

如何要求多个条件返回真正的Java

我正在编写一个必须符合前提条件的代码,如果条件都满足,那么它将返回true.我尝试了多个"if"语句,但这似乎不起作用.嵌套if语句似乎不是这里的答案,我不认为"else if"语句可行.我要问的是,这样做的正确方法是什么?我写if语句错了吗?

继承我的代码:

public static boolean isLegitimate(int mon, int day, int year){

    // February has 29 days in any year evenly divisible by four,
    // EXCEPT for centurial years which are not also divisible by 400.


    // TODO 1: Check if a date is valid.

    //checks to see if the months are between 1 and 12
    if((mon >= 1) && (mon <= 12)) {

    }
    //checks to see if the years are greater than 1
    if (year > 0){

    } …
Run Code Online (Sandbox Code Playgroud)

java preconditions

3
推荐指数
1
解决办法
1070
查看次数

标签 统计

java ×1

preconditions ×1