File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question from Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question from" Watch "question from" New topic

question from

hans raj

Joined: Jul 05, 2001
Posts: 3
anyone tell me the solution for this question found at
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);�
�������� }

also please suggest me some good books available.
Gaurav Goyal

Joined: Jul 04, 2001
Posts: 20
there are 4 errors in the code
1) the class name cant be short as it is a keyword.
2)argument in the main method is wrong it should be String args[]
3) variable t is declared twice
4) undefined variable i
Mikael Jonasson
Ranch Hand

Joined: May 16, 2001
Posts: 158
I'm guessing that you did a typo and it is int i=0; not int t=0;
Anyway, the | | operator is design so that if the firts part is true, the second part is never evaluated.
This means that the line b=(t | | ((i++) ==0)); only sets b to true, sice t is true.
The second line, where f is false, evaluates the i+=2 part, seting i to 2. Since 2 is larger then 0, b is asigned true again.
hans raj

Joined: Jul 05, 2001
Posts: 3
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
Check the Bunkhouse for good books. Also, you should compile your code before posting. It will help get more meaningful answers.

Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
srinivas bolloju
Ranch Hand

Joined: Jan 23, 2001
Posts: 112
if it was int i=0; in the declaration,
then the answer is 2 when u execute the class right?

please use the [code][/code] tags when showing code. visit <a href="" target="_blank" rel="nofollow"></a> ,for more details
hans raj

Joined: Jul 05, 2001
Posts: 3
Hi ,
thankyou paul for ur suggestion, iam new to this site , i will certainly do it before i post some code.
I agree. Here's the link:
subject: question from
It's not a secret anymore!