Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

please tell me the output

 
prabhash singh
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Above,

It prints That's Java, That's crazy, That's different.
[ November 07, 2006: Message edited by: Jothi Shankar Kumar Sankararaj ]
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ]
 
Joe Harry
Ranch Hand
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 72
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Sanjeev Singh
Ranch Hand
Posts: 381
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10106
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Sanjeev,

I have given my O/P in my post itself. By the way, I have sent an email to you.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic