wood burning stoves 2.0*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes please tell me the output Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "please tell me the output" Watch "please tell me the output" New topic
Author

please tell me the output

prabhash singh
Greenhorn

Joined: Jun 05, 2006
Posts: 19
Hi All,
can you please explain the output in the program below:-

What will be output of the following code: Really interesting



public class test{

public static void main(String args[]){

Integer a1=1000;

Integer a2=1000;

if(a1!=a2){

System.out.println("That�s Java ");
}

if(a1==a2 && a1!=a2){// note this is very confusing.. will you ever think this condition will satisfy?

System.out.println("That�s Java ");

}else{

System.out.println(" That�s crazy ");

}

if(a1!=a2){

System.out.println("That�s different ");
}

if(a1==a2){

System.out.println(" Its Equal");
}

}

}

Thanks in advance,

regards,
Prabhash Kumar
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Above,

It prints That's Java, That's crazy, That's different.
[ November 07, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]

SCJP 1.4, SCWCD 1.4 - Hints for you, SCBCD Hints - Demnachst, SCDJWS - Auch Demnachst
Did a rm -R / to find out that I lost my entire Linux installation!
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
The most disscussed Topic!
http://www.coderanch.com/t/260198/java-programmer-SCJP/certification/wrapper-objects-equals

Here is one more:
http://www.coderanch.com/t/260163/java-programmer-SCJP/certification/String-Class-Wrapper-Class

There are more SOPs at the end,Jothi :roll:
[ November 07, 2006: Message edited by: Sanjeev Kumar Singh ]

~Sanjeev Singh<br />SCJP 1.5
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Now try this and tell me what it prints??


Got it??? yes it prints,

That�s Java
That�s Java
That�s crazy
That�s different
Its Equal
[ November 07, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
Still not got The original program will print
That�s Java
That�s different

Now dig into the matter and find how?
Saurabh Vyas
Ranch Hand

Joined: Sep 02, 2003
Posts: 72
The o/p should be
That�s Java [ from the first if -- ie if(a1!=a2) ]
That�s crazy [ from else part of second if -- ie else of if(a1==a2 && a1!=a2) ]
That�s different [ from third if -- ie if(a1!=a2) ]
Priyam Srivastava
Ranch Hand

Joined: Oct 29, 2006
Posts: 169
That's Java (from condition if(a1!=a2) )
That's crazy ( from else part)
That's Different (if(a1!=a2))







yeah this is certainly the most discussed topic..
check this link;
http://www.coderanch.com/t/260163/java-programmer-SCJP/certification/String-Class-Wrapper-Class


"History would be kind to me, for I intend to write it."
Sanjeev Singh
Ranch Hand

Joined: Nov 01, 2006
Posts: 381
This is the output of jothi program which he has written with a lot of alteration in original program.look closely the ; after the conditonal if's and loops for.
Joe Harry
Ranch Hand

Joined: Sep 26, 2006
Posts: 9243
    
    1

Hi Sanjeev,

I have given my O/P in my post itself. By the way, I have sent an email to you.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: please tell me the output
 
Similar Threads
How many Objects are elligible for Gabbage Collection at Line 17?
String operation
exam lab gc question
Please explain what does mean by static references to objects
int -> float -> int and loss of precision