aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question from anilbachi site Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question from anilbachi site" Watch "question from anilbachi site" New topic
Author

question from anilbachi site

madhu kumar
Greenhorn

Joined: Jan 05, 2001
Posts: 20
hi this question is from http://www.anilbachi.8m.com .
Please help me with solution.
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
I think the answer is 2. Am I right. Please help me.
Kalpesh Pandya
Greenhorn

Joined: Oct 07, 2000
Posts: 14
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.
madhu kumar
Greenhorn

Joined: Jan 05, 2001
Posts: 20
Thanks kalpesh
Noel Hinders
Ranch Hand

Joined: Jan 13, 2001
Posts: 44
Hi
I too guess that it should be int i=0 then the answer would be 0.
Noel
Jonathan Li
Greenhorn

Joined: Feb 05, 2001
Posts: 4
actually the question is wrong. the code does not compile at all because you're using a keyword (short) as the class name.
Golam Newaz
Ranch Hand

Joined: Jan 08, 2001
Posts: 64
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

Joined: Jan 13, 2001
Posts: 44
Hi,
vow I did not even notice it,
I guess that makes the difference
Noel
venu gopal
Ranch Hand

Joined: Nov 21, 2000
Posts: 40
Madhu,
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).]
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: question from anilbachi site