【问题标题】: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 &lt; 12 将始终评估为 true。

    【讨论】:

    • 谢谢,我很感激,我只是用它作为例子:)
    【解决方案2】:

    我问

    if( x > y || 10 < 12) { 
    System.out.println("one of these is true"); 
    }
    

    应该做的事情。

    【讨论】:

      猜你喜欢
      • 2017-04-15
      • 1970-01-01
      • 2012-12-01
      • 1970-01-01
      • 2012-01-10
      • 2013-06-07
      • 2010-12-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多