943,864 Members | Top Members by Rank

Ad:
  • Java Discussion Thread
  • Marked Solved
  • Views: 4137
  • Java RSS
Jun 5th, 2009
0

Inverting value of boolean variable?

Expand Post »
Hi guys,

I am using boolean variables as flags in a program and i want to be able to invert the value.

for example if the current value is true, then it must be changed to false; doesn't matter if i don't know what the current value is.
Similar Threads
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
redZERO is offline Offline
81 posts
since Dec 2007
Jun 5th, 2009
2

Re: Inverting value of boolean variable?

Click to Expand / Collapse  Quote originally posted by redZERO ...
Hi guys,

I am using boolean variables as flags in a program and i want to be able to invert the value.

for example if the current value is true, then it must be changed to false; doesn't matter if i don't know what the current value is.
Use the ! operator.

Java Syntax (Toggle Plain Text)
  1. boolean a = true;
  2. System.out.println (Boolean.toString(a)); // true
  3. a = !a;
  4. System.out.println (Boolean.toString(a)); // false
Featured Poster
Reputation Points: 2614
Solved Threads: 687
Posting Expert
VernonDozier is offline Offline
5,375 posts
since Jan 2008
Jun 5th, 2009
0

Re: Inverting value of boolean variable?

Excellent, thank you very much!
Reputation Points: 10
Solved Threads: 2
Junior Poster in Training
redZERO is offline Offline
81 posts
since Dec 2007

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Java Forum Timeline: Penny Pitch Game
Next Thread in Java Forum Timeline: Please help me with the program code





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC