aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Logical AND ,OR operators Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Logical AND ,OR operators" Watch "Logical AND ,OR operators" New topic
Author

Logical AND ,OR operators

ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Boolean b1 = true;
boolean b2 = false;
boolean b3 = true;

Can any one explain the Logical AND, OR operators with all combinations
like...

b1&b2= ?
b1|b2= ?
b1&b1= ? like this in all combinations..
Thanks in advance.
R van Vliet
Ranch Hand

Joined: Nov 10, 2007
Posts: 144
I'm erring towards telling you to simply google this stuff since the first hit on my screen adequately explains it, but i'm in a good mood, so :

& (AND) operator returns true if and only if both operands are true, so :




| (OR) operator returns true if either operand is true, so :





^ (XOR) operator returns true if the operands are unequal, so :

ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi I had Little bit confusion..If you don't mind can any one explain please.

Boolean b1 = true;
boolean b2 = false;
boolean b3 = true;


why this if((b1 = false) | (b1 & b3) | (b1 | b2)) is returning the false....I am thinking this will return true..like this

b1 = false) | (b1 & b3) | (b1 | b2)
------------|-----------| ---------
false | true | false
------------------------|------
true |false = true

but when test this this is returning the false
If there is any wrong in my evaluation...Please any one explain.
Thanks in advance.
Luca Romanello
Greenhorn

Joined: May 30, 2002
Posts: 11
Originally posted by ishmayel vemuru:
Hi I had Little bit confusion..If you don't mind can any one explain please.

Boolean b1 = true;
boolean b2 = false;
boolean b3 = true;


why this if((b1 = false) | (b1 & b3) | (b1 | b2)) is returning the false....I am thinking this will return true..like this

b1 = false) | (b1 & b3) | (b1 | b2)
------------|-----------| ---------
false | true | false
------------------------|------
true |false = true

but when test this this is returning the false
If there is any wrong in my evaluation...Please any one explain.
Thanks in advance.


Hi Ishmayel
Pay attention to the first part of your boolean expression: it's b1 = false and not b1 == false. This means that you are assigning to b1 the value false, thus returning the result of the assignment (again false). After the first part is evaluated, comes the second term, b1 & b3, which return false and not true, 'cause now b1 isn't true anymore.
Hope this helps
Regards
LR
ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi Luca Romanello Please just see the Logical AND ,OR operators
based on that I am anlysing the problems Please check the above poset once..

|b1 | b2 | & result |
|-------+-------+----------|
| false | false | false |
| false | true | false |
| true | false | false |
| true | true | true |
Thanks in advance..
Ishmayel.
Luca Romanello
Greenhorn

Joined: May 30, 2002
Posts: 11
Sorry, Ishmayel, but I'm missing your point here.
From what you write, it seems to me we're not understanding each other on the boolean operation you wrote in your post.
Maybe with a little example my thought is clearer:
( (b1 = false) | (b1 & b3) | (b1 | b2) ) => returns false
( (b1 == false) | (b1 & b3) | (b1 | b2)) => returns true
Hope this helps (unless at this point of the day I am too tired to think properly... )
Regards
LR
ishmayel vemuru
Ranch Hand

Joined: Jun 13, 2007
Posts: 46
Hi Luca Romanello thank you very much...
Now I understood my mistake where I think wrongly thank you once again.
with Regards..
Ishmayel.
[ November 21, 2007: Message edited by: ishmayel vemuru ]
veda vyas sista
Greenhorn

Joined: Sep 21, 2007
Posts: 10
One important point to remember when solving these type of questions is deciding what is the value of the variable when it is not declared that is whether it is a member variable or local variable
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Logical AND ,OR operators