简体   繁体   English

否则没有如果布尔错误

[英]else no if boolean error

Wondering if someone could help see why this is returning an error on there being an else without an if.想知道是否有人可以帮助了解为什么在没有 if 的情况下会返回错误。 I have tried looking at other questions to no avail我试过查看其他问题无济于事

public boolean isLate()   {
if( done = false); AND (deadline.hasPassed = true);   {
return true;
} else{
    return false;}
}

AND is not correct. AND不正确。 It must be replaced by && and move inside the ìf definition.它必须由&&替换并移动到ìf定义内。 Moreover use == to compare instead of =此外使用==来比较而不是=

if(done == false && deadline.hasPassed == true) {
    return true;
} else {
    return false;
}

Because done and deadline.hasPassed seem to be booleans, you can simplify it writting ( ! means not )因为donedeadline.hasPassed似乎是布尔值,您可以简化它的编写( !表示not

if(!done && deadline.hasPassed) {
    return true;
} else {
    return false;
}

Which can be simplify as可以简化为

public boolean isLate()   {
    return !done && deadline.hasPassed;
}

The thing you are looking for is:你要找的东西是:

public boolean isLate() {
    return ((done == false) && (deadline.hasPassed == true));
}

But this kind of basic understanding in java can be googled!不过这种基本的java理解可以google一下!

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM