Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to change a boolean from true to false

807597Jan 16 2005 — edited Jan 16 2005
Hi, I have been searching for the answer to this for some time now but just cannot find it, I need to do this for a training exercise ( I have just started to learn Java, and I am new to programming as well)

"If there have been any warnings, write out a final error message. (To do this, declare a boolean variable goodPressure that is initialized to true but is changed to false when an out of range tire is first found.)"

Can I do this with an exising if else, the notes I have do not offer any explanation on how to do this.
I have made an attempt, using this

if (rfp < 35 || rfp >45 )
goodPressure = false
System.out.println(" The tyre pressure is out of range ");

and then at the end

if (goodPressure = true )
System.out.println(" Tyre pressures are ok ");
else
System.out.println(" Tyre pressures are bad ");

When I run the program and enter the values for each tyre, I can get the "out of range" message working, but nothing seems to happen with the "Tyre pressures are bad" message, all I get is the "Tyre pressures are ok" message, regardless of the values that are entered.

I must be doing it wrong somehow, but cannot find out hwat I am doing wrong.

Thanks very much for any help.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Feb 13 2005
Added on Jan 16 2005
5 comments
1,660 views