*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes question from javacross.com Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "question from javacross.com" Watch "question from javacross.com" New topic
Author

question from javacross.com

hans raj
Greenhorn

Joined: Jul 05, 2001
Posts: 3
Hello,
anyone tell me the solution for this question found at www.javacross.com
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.
thankyou.
Gaurav Goyal
Greenhorn

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
thanku
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.
ok?
/Mike
hans raj
Greenhorn

Joined: Jul 05, 2001
Posts: 3
thankyou.
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="http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page" target="_blank" rel="nofollow">http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=ubb_code_page</a> ,for more details
hans raj
Greenhorn

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.
Hans
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: question from javacross.com
 
Similar Threads
what's the output
question from anilbachi site
Short circuit operators
Operator question
javaprepare question