Why does my boolean test in java always fail?

后端 未结 6 1398
别跟我提以往
别跟我提以往 2021-01-21 21:59

I am trying to make a boolean test so that if one of the tire pressures is below 35 or over 45 the system outputs \"bad inflation\".

In my class I must use a boolean, wh

6条回答
  •  孤城傲影
    2021-01-21 22:26

    It looks like you're never setting goodPressure to true. Maybe you want to start with it set to true, as it looks like your conditions will set it to false if necessary.

    Also, I think this line should throw a compiler warning (or error?)

    if (goodPressure = true)
    

    when compiling in Java. I thought the compiler wouldn't let you do an assignment in an if check, but maybe it does... I think you want it to be:

    if (goodPressure == true)
    

    Or just:

    if (goodPressure)
    

提交回复
热议问题