File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Logical AND ,OR operators

 
ishmayel vemuru
Ranch Hand
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 144
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 46
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic