Sam*_*Sam 1 java spring loops if-statement
我正在尝试:如果abb.iscurrentlyy()返回true,则进入if语句或abb.islately()为true。
我的 if 语句有什么问题?当我设置abb.iscurrentlyy()为false时。abb.islately()设置为真。为什么abb.iscurrentlyy()进入循环甚至abb.iscurrentlyy()是假的?
if (abb.iscurrentlyy() || abb.islately()) {
if (reqFiles != null) {
for (int i = 0; i < reqFiles.length; i++) {
Future<ExecResult> lcukv = executor.submit(worker);
executionFutureException.add(lcukv);
}
}
} else { // do if condition is false.
}
Run Code Online (Sandbox Code Playgroud)
术语or(||) 表示要使条件为真,至少一个子条件必须为真。
boolean condition1 = true;
boolean condition2 = false;
if(condition1 || condition2)
{
System.out.println("One or both conditions were true");
}
else
{
System.out.println("Both conditions were false");
}
Run Code Online (Sandbox Code Playgroud)
在现实世界中,想象一下走进一家冰淇淋店。你喜欢草莓冰淇淋。你也喜欢巧克力冰淇淋。你讨厌所有其他口味。如果这家商店至少有其中一种口味,你会很高兴。
您的代码类似于上面的示例。另一方面,如果您希望在一个条件为真而另一个为假时为假,请使用and(&&)。
boolean condition1 = true;
boolean condition2 = false;
if(condition1 && condition2)
{
System.out.println("Both conditions were true");
}
else
{
System.out.println("At least one condition was false");
}
Run Code Online (Sandbox Code Playgroud)
在这种情况下,冰淇淋店必须有你喜欢的两种口味才能让你开心。
认为or更宽容:“我可以让这个或那个成为真的。” and,然而,听起来很包容,但实际上更排外:“我必须有这个和那个才是真的。”
| 归档时间: |
|
| 查看次数: |
662 次 |
| 最近记录: |