Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/joomla/2.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 括号归约_Java - Fatal编程技术网

Java 括号归约

Java 括号归约,java,Java,我写了以下内容: if ( ( ( weight < 160 && ( age <= 27 && age >= 22 ) ) && ( ( height < 72 ) && ( ( !isASmoker ) && ( isMale ) ) ) && ( ( isGoodLooking ) && ( isAbleToRelocate) ) ) )

我写了以下内容:

if ( ( ( weight < 160 && ( age <= 27 && age >= 22 ) )
    && ( ( height < 72 ) && ( ( !isASmoker ) && ( isMale ) ) )
    && ( ( isGoodLooking ) && ( isAbleToRelocate) ) ) ) {
if((体重<160&(年龄=22))
&&((身高<72)和(!Isamoker)和((isMale)))
&&((isGoodLooking)和&(isAbleToRelocate))){
我可以减少括号吗


谢谢

如果您正确理解了java运算符的优先级,则可以将其缩减为最小括号:

if ( ( weight < 160 && ( age <= 27 && age >= 22 ) )
&& (  height < 72  &&  !isASmoker  &&  isMale )
&& (  isGoodLooking  &&  isAbleToRelocate ) ) {
if((体重<160&(年龄=22))
&&(身高<72&&!Isamale)
&&(isGoodLooking&IsabletoreLocation)){
有关更多信息,请参阅

<>编辑:-实际上,如果你考虑如果条件“和”操作符检查下一个条件,如果第一个是真,那么逻辑上可以进一步降低到

if ( weight < 160 &&  age <= 27 && age >= 22 
&&  height < 72  &&  !isASmoker  &&  isMale 
&&  isGoodLooking  &&  isAbleToRelocate ) {
if(体重<160岁年龄=22岁
&&身高<72&&!Isamer&&isMale
&&isGoodLooking&&IsabletoreLocation){
如中正确所述,您实际上可以删除除外部括号外的所有括号

if  (weight < 160 && age <= 27 && age >= 22 
        && height < 72 &&   !isASmoker  &&  isMale   
        &&   isGoodLooking  &&  isAbleToRelocate  )
if(体重<160岁年龄=22岁
&&身高<72&&!Isamer&&isMale
&&isGoodLooking&&IsabletoreLocation)

这是你可以使用的最小数量。最大数量是…嗯,实际上是无限的(显然是有限的,但可能性是无限的)。您可以添加任意数量的内容,只要它实际上是正确的。

是的,您当然可以。您尝试过吗?您只使用了
&&
,所以是的。基本上,您可以删除除外括号以外的所有内容。但您不应该设计这样的
if
子句。这会导致无法维护代码。为什么您在首先?为什么不创建两个方法并从if语句调用它们呢?这将使它更易于维护和阅读。如果您认为它可以减少更多,因为它只是和。只有外圆括号应该无关紧要吗?您不需要任何内圆括号,事实证明,即使没有圆括号,它也可以工作除了oneNow,它更好!@austinwernli这句话不是你说的,但我经常在没有任何解释的情况下,在问题或答案上获得选票,这有时会驱使我crazy@LonniBesançon我只是错过了这一点……顺便说一句,谢谢你删除的评论;)