File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes boolean operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "boolean operators" Watch "boolean operators" New topic
Author

boolean operators

vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
hello guys, 2 questions i would like to ask on boolean operations:

1. Is there any operators that can be used with boolean data types?

2. I am trying to do a comparison between 2 boolean type variable to get the result, like this:

if a is true, b is true then c is true,
else c is false.

I know this can be done by using an if/else , how about arithmetic operations or other methods if possible?


I'm not available, my BF's name is WORK.
Garrett Rowe
Ranch Hand

Joined: Jan 17, 2006
Posts: 1296
if a is true, b is true then c is true,
else c is false.



[ May 09, 2006: Message edited by: Garrett Rowe ]

Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by vivien siu:
...how about arithmetic operations or other methods if possible?

Note that in Java, boolean values cannot be treated arithmetically.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
Jeff Albertson
Ranch Hand

Joined: Sep 16, 2005
Posts: 1780
Originally posted by vivien siu:

1. Is there any operators that can be used with boolean data types?


I can only think of 13:

boolean a = x && y;
boolean b = x || y;
boolean c = x & y;
boolean d = x | y;
boolean e = x == y;
boolean f = x != y;
boolean g = x ^ y;
boolean h = (x = y);
boolean i = (x &= y);
boolean j = (x |= y);
boolean k = (x ^= y);

boolean l = !x;
boolean m = x ? y : !y;


There is no emoticon for what I am feeling!
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
Wonder why they left out &&=. I really wanted it yesterday.


A good question is never answered. It is not a bolt to be tightened into place but a seed to be planted and to bear more seed toward the hope of greening the landscape of the idea. John Ciardi
stevie liu
Greenhorn

Joined: Mar 26, 2004
Posts: 6
how to use '&&='
I think '&&=' can't be used in boolean.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18552
    
  40

Originally posted by Stan James:
Wonder why they left out &&=. I really wanted it yesterday.


Hmmm... interesting... So, if the left side is true, it will assign it to the right side. Otherwise, it will short circuit the expression. Sort of like this.



Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
vivien siu
Ranch Hand

Joined: Nov 10, 2005
Posts: 143
OMG, got such operators like "&&=" ???

How does this work? Does operators like this come out in SCJP exams?
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 18552
    
  40

Originally posted by vivien siu:
OMG, got such operators like "&&=" ???

How does this work? Does operators like this come out in SCJP exams?


Don't panic. There is no such operator. If you reread the thread, you'll notice that it was about how that operator is missing...

Henry
Stan James
(instanceof Sidekick)
Ranch Hand

Joined: Jan 29, 2003
Posts: 8791
I just wanted shorthand for

bool = bool && testone();
bool = bool && testtwo();
bool = bool && testthree();

The real test expressions were long enough they did not read well as

bool = testone() && testtwo() && testthree();
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: boolean operators
 
Similar Threads
Trouble with Jqplus Question
question about &&
compound assignment operator doubt
Operators and Precedence
why Float.NaN and Double.NaN?