Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/323.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/symfony/6.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java:使int和boolean在“中具有可比性”;如果;声明_Java_Boolean - Fatal编程技术网

Java:使int和boolean在“中具有可比性”;如果;声明

Java:使int和boolean在“中具有可比性”;如果;声明,java,boolean,Java,Boolean,有没有可能有一种说法,比如 if(delco == 1 && heavy < 5) System.out.println("The total cost of your delivery is: $" + OPT_ONE); if(delco == 1 && heavy >= 5 && heavy <= 20) System.out.println("The total cos

有没有可能有一种说法,比如

     if(delco == 1 && heavy < 5)
         System.out.println("The total cost of your delivery is: $" + OPT_ONE);
     if(delco == 1 && heavy >= 5 && heavy <= 20)
        System.out.println("The total cost of your delivery is: $" + OPT_TWO);
if(delco==1&&heavy<5)
System.out.println(“交付的总成本为:$”+OPT_ONE);

如果(delco==1&&heavy>=5&&heavy=5&&heavy您只是遗漏了一些括号,因为您的逻辑似乎正常。它应该是,例如:

if ( (delco == 1 && heavy < 5) && (overnightShip == YES) )
    ...
在这种情况下,这些括号也是多余的,整个过程简化为:

if ( delco == 1 && heavy < 5 && overnightShip )
    ...
if(德尔科==1和重型<5和过夜船)
...

只需单独使用布尔值即可:

if (delco == 1 && heavy < 5 && overnightShip)
if(德尔科==1和重型<5和过夜船)

将布尔“标志”变量与布尔常量进行比较是一种糟糕的风格-始终更喜欢按原样测试布尔值。

Java中的布尔类型具有以下值:

true
false
不是:

除非你自己在某个地方定义了这些常量

因此,您的代码应该如下所示:

(overnightShip == true)
(overnightShip == false)
甚至:

(overnightShip)    // true
(! overnightShip)  // false

夜航
的类型是什么?此外,如果条件满足,则在整个
条件周围加上括号。
YES
NO
(overnightShip == true)
(overnightShip == false)
(overnightShip)    // true
(! overnightShip)  // false