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:
• Tim Cooke
• Campbell Ritchie
• Ron McLeod
• Junilu Lacar
• Liutauras Vilda
Sheriffs:
• Paul Clapham
• Jeanne Boyarsky
• Henry Wong
Saloon Keepers:
• Tim Moores
• Tim Holloway
• Stephan van Hulst
• Piet Souris
• Carey Brown
Bartenders:
• Jesse Duncan
• Frits Walraven
• Mikalai Zaikin

# question from anilbachi site

Greenhorn
Posts: 20
• Number of slices to send:
Optional 'thank-you' note:
hi this question is from http://www.anilbachi.8m.com .
Q}State the output of the following code
public class short{
public static void main(String args()){
int t=0;
boolean t=true;
boolean f=false,b;
b=(t | | ((i++) ==0));
b=(f | | ((i+=2)>0));
System.out.println(i);
}}
a).0
b).1
c).2
d).3

Greenhorn
Posts: 14
• Number of slices to send:
Optional 'thank-you' note:
Hi,
First of all instead of int t = 0, it should be int i = 0.
If it is so, you are right, what's the problem ???
in first statement: b=(t | | ((i++) ==0)), as t is true, i++ never get executed, so i remains 0. rest of it is simple.

Greenhorn
Posts: 20
• Number of slices to send:
Optional 'thank-you' note:
Thanks kalpesh

Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
Hi
I too guess that it should be int i=0 then the answer would be 0.
Noel

Greenhorn
Posts: 4
• Number of slices to send:
Optional 'thank-you' note:
actually the question is wrong. the code does not compile at all because you're using a keyword (short) as the class name.

Ranch Hand
Posts: 64
• Number of slices to send:
Optional 'thank-you' note:
Hi,
I agree with Jonathan. Question is wrong as it has been
used keyword ( short ). Output is nothing. Yes if you
correct variable then you would get 2.
- Golam Newaz

Noel Hinders
Ranch Hand
Posts: 44
• Number of slices to send:
Optional 'thank-you' note:
Hi,
vow I did not even notice it,
I guess that makes the difference
Noel

Ranch Hand
Posts: 40
• Number of slices to send:
Optional 'thank-you' note:
The answere is 2. There should not be a space between short circuit operator. Please keep in mind while executing the code.
public class short1{
public static void main(String args[]){
int i=0;
boolean t=true;
boolean f=false,b;
b=(t | | ((i++) ==0));
System.out.println(b);
b=(f | | ((i+=2)>0));
System.out.println(b);
System.out.println(i);
}
}

[This message has been edited by venu gopal (edited February 06, 2001).]