【问题标题】:is there an equivalent if statement in java as this python one?java中是否有与此python等效的if语句?
【发布时间】:2022-06-30 16:20:07
【问题描述】:
我通常编写 python 代码,但决定尝试学习一门新语言 (Java)。我是一个完整的初学者,有大约 2 小时的经验。在 python 中,我们可以使用“或”,这样如果满足一个条件,它就会执行代码块。EG:
if x>y or 10<12:
print("one of these is true")
在 java 中有没有等价物?
【问题讨论】:
标签:
java
conditional-statements
boolean
【解决方案1】:
等效的 if 语句是
if (x > y || 10 < 12) {
....
}
或者,您可以跳过它,因为 10 < 12 将始终评估为 true。
【解决方案2】:
我问
if( x > y || 10 < 12) {
System.out.println("one of these is true");
}
应该做的事情。