programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
• Campbell Ritchie
• Tim Cooke
• Ron McLeod
• Jeanne Boyarsky
• Paul Clapham
Sheriffs:
• Liutauras Vilda
• Henry Wong
• Devaka Cooray
Saloon Keepers:
• Tim Moores
• Stephan van Hulst
• Tim Holloway
• Al Hobbs
• Carey Brown
Bartenders:
• Piet Souris
• Mikalai Zaikin
• Himai Minh

# Satou kurinosuke i have one more question for you

Ranch Hand
Posts: 176
• • Number of slices to send:
Optional 'thank-you' note:
• • boolean y= (a1=false)&&(a2=true)||(a3=true);
accordingly this should return false na
i.e y=false a1 false a2 false a3 false if a1 a2 a3 are static fields in a class but it is printing true false false true.

Ranch Hand
Posts: 1704
• • Number of slices to send:
Optional 'thank-you' note:
• • Originally posted by bnkiran kumar:
boolean y= (a1=false)&&(a2=true)||(a3=true);
accordingly this should return false na
i.e y=false a1 false a2 false a3 false if a1 a2 a3 are static fields in a class but it is printing true false false true.

y is true because
the following line:
y= (a1=false)&&(a2=true)||(a3=true); =>
y= ((a1=false)&&(a2=true))||(a3=true);

is equal to y = ((false) && (true)) ||(true);=>
y = false || true => y = true

Edited to correct the values.
[ March 14, 2006: Message edited by: KJ Reddy ]

bnkiran kumar
Ranch Hand
Posts: 176
• • Number of slices to send:
Optional 'thank-you' note:
• • but if in && short circuit operator if left hand operand is false then right will not be evaluated na....

Kj Reddy
Ranch Hand
Posts: 1704
• • Number of slices to send:
Optional 'thank-you' note:
• • You are correct but "&&" operator do not stop evaluating "||" operator and in Java the expression will be evaluated from left. So first
(a2=true)||(a3=true) will be evaluate which returns true.
Then (a1=false)&& true will be evaluated which returns false.

bnkiran kumar
Ranch Hand
Posts: 176
• • Number of slices to send:
Optional 'thank-you' note:
• • sorry reddy i did get you,
actually in the question b=(x=true)||(y=true)&&(z=true);
in this || is preventing y and z from evaluating as it is a shortcircuit operator(for || if lefhand operand is true and for && if left hand operand is false, then right will not be evaluated na)

as for above b=(x=true)||((y=true)&&(z=true));so answer is justified,for my quesion which asked previously ,result should be false na as left hand operand itself is false!!!

Kj Reddy
Ranch Hand
Posts: 1704
• • Number of slices to send:
Optional 'thank-you' note:
• • Sorry I am not getting you. Can you post your entire code so that I can understand what you are trying to do.

y is flase in your question.

bnkiran kumar
Ranch Hand
Posts: 176
• • Number of slices to send:
Optional 'thank-you' note:
• • class EBH202 {
static boolean a, b, c;
public static void main (String[] args) {
boolean x = (a = true) || (b = true) && (c = true);
System.out.print(a + "," + b + "," + c);
}}

after seeing this i think you get an idea of my original question i asked i.e is x=(a=false)&&(b=true)||(c=true);

Kj Reddy
Ranch Hand
Posts: 1704
• • Number of slices to send:
Optional 'thank-you' note:
• • The above program will print true, true, true.

boolean y= (a1=false)&&(a2=true)||(a3=true);
If you analyse above line,

move from left to right
boolean y= (a1=false)&&(a2=true)||(a3=true);
boolean y= ((a1=false)&&(a2=true))||(a3=true);
boolean y= false ||(a3=true); => a1 = false, a2 = false as a2 is not getting evaluated becaue of && and it retains orginal value.
boolean y= true => a3 = true;

I assume that a1, a2, a3 values are false initially

bnkiran kumar
Ranch Hand
Posts: 176
• • Number of slices to send:
Optional 'thank-you' note:
• • thank you reddy.

Kj Reddy
Ranch Hand
Posts: 1704
• • Number of slices to send:
Optional 'thank-you' note:
• • Sorry my initial comments are not clear and I modified my comments
[ March 14, 2006: Message edited by: KJ Reddy ]

Sheriff Posts: 14691
16   • • Number of slices to send:
Optional 'thank-you' note:
• • Thanks KJ.
Sorry bnkiran, I was not logged in anymore  With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.