SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
salvin francis wrote:check the other conditions.
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
System.out.println((a=false) && (b=false) && (c=false));
System.out.println(a+" "+b" "+c);
will result in
false
false true false
System.out.println((a=false) && (b=false) || (c=false));
System.out.println(a+" "+b" "+c);
Soniya Ahuja wrote:.Actually, I wasn't wondering about the precedence.
...
So I want to know why is && evaluated further beyond the second result
That applies when you use && for AND.salvin francis wrote:Hint: In an "AND" expression, if one condition is false, the machine never bothers to even check the other conditions.
In an and expression
You may not be wondering about precedence, but in order to understand what is going on, you'll need to understand precedence. The logical AND has higher precedence than the logical OR -- so this...
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
I hope you are mistaken about having seen that. It is incorrect.Soniya Ahuja wrote:I had read somewhere that in Java && and || take equal precedence.
Campbell Ritchie wrote:
I hope you are mistaken about having seen that. It is incorrect.Soniya Ahuja wrote:I had read somewhere that in Java && and || take equal precedence.
You will have to go through that confusing code you wrote with all the side-effects with a pencil and see how many of those assignments are ever executed.
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
By the way: you are not using logical AND or logical OR. You are using conditional AND && and conditional OR ||. But conditional AND still has a higher precedence than conditional OR.
Soniya Ahuja wrote:I was thinking that only one assignment has taken place - a=true. Well, if other assignments were to happen, wouldn't the values of the variables change? Oh, someone please explain it vividly
Soniya Ahuja wrote:HI salvin,
= and == are different. Only boolean assignments can be used in boolean expressions. Other assignements like integer assingments cannot be used. Boolean assignments can be used because the result of a boolean assignment is a boolean value.
salvin francis wrote:
Soniya Ahuja wrote:HI salvin,
= and == are different. Only boolean assignments can be used in boolean expressions. Other assignements like integer assingments cannot be used. Boolean assignments can be used because the result of a boolean assignment is a boolean value.
I was merely remarking on your program:
when you mention a=true, what do you expect to happen : assignment or a conditional check ?
The output of the program is justified, but it seems you didnt intent it to be so.
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
SCJP 1.5 | SCWCD 5 | SCJP 6.0
[url]http://a2zjava.webs.com[/url] - Online training for Java/JSPs and Servlets/SCJP/SCWCD
http://soniyaahuja.webs.com
There is no beard big enough to make me comfortable enough with my masculinity to wear pink. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
|