1

这不是针对特定代码的,我只是好奇。关系运算符如==, <, >, >=, <=, !=.

4

5 回答 5

2

当然:

if (processing)
{
    // enter if the boolean processing is true
}
于 2013-06-04T01:04:55.023 回答
0

假设您有一个返回布尔值的函数

  public boolean isTrue()
  {
    //Some code
    //return true or false

  }

然后'if'语句将如下所示:

  if(isTrue())
     //Do something
  else
    //Do something else
于 2013-06-04T01:10:19.460 回答
0

实际上,if 语句只知道它是真值还是假值。
但在整数的情况下,如果括号内的内容正确,则返回 x true。
喜欢:

int n=10;  
if(n==10){}

括号内的值将返回 true,因为它是正确的。如果将括号更改为n>10

不同的条件适用于字符串..

于 2013-06-04T01:14:05.303 回答
0

是的:

if (x) {
    ...
}

或者

if (!x) {
    ...
}

wherex是一个布尔值或任何返回布尔值的东西。

哎呀,发疯:

boolean x = false, y = false;

if (x = y = x = !y) {

}

(请注意,我们在这里使用的是=not ==- 如果有的话,您可能很少想做这样的事情。)

于 2013-06-04T01:16:56.347 回答
0

是的。一般来说,if语句的语法是if (cond) { xxx(); }where condis any expression that evaluates to aboolean

这意味着以下都是有效的:

if (true)           // Literal value true
if (m.find())       // m is a Matcher; .find() returns true if match
if (3 <= 3)         // operator
if (a && b)         // a and b are expressions evaluating to a boolean;
                    // && is the logical "and" operator

等等。

于 2013-06-04T01:58:02.850 回答