Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Doubt Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCM Java EE 6 Enterprise Architect Exam Guide this week in the OCMJEA forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Doubt" Watch "Doubt" New topic
Author

Doubt

Rajan Narayanan
Greenhorn

Joined: Aug 07, 2000
Posts: 16
public class Ex2 {
public static void main (String args[]) {
int a = 4;
System.out.println("Value is "+
((a>4) ?99.99:9));
}
}
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Originally posted by Rajan Narayanan:
public class Ex2 {
public static void main (String args[]) {
int a = 4;
System.out.println("Value is "+
((a>4) ?99.99:9));
}
}

__________________________________________________
The o/p is : Value is 9.0

Savithri Devaraj
Ranch Hand

Joined: Jun 26, 2000
Posts: 103
Originally posted by Rajan Narayanan:
public class Ex2 {
public static void main (String args[]) {
int a = 4;
System.out.println("Value is "+
((a>4) ?99.99:9));
}
}

Already discussed here http://www.javaranch.com/ubb/Forum24/HTML/003095.html
Savithri
Rajan Narayanan
Greenhorn

Joined: Aug 07, 2000
Posts: 16
Hi!
Thnx for ur reply, but when i compiled and run it shows only 9 not 9.0 , can u explain out the reason.
Thnx
Rajan
daryl olson
Ranch Hand

Joined: Aug 15, 2000
Posts: 36
Rajan,
Are you sure it returned 9?
I tried it and it returned 9.0 as expected (under 1.2.2).
Rajan Narayanan
Greenhorn

Joined: Aug 07, 2000
Posts: 16
i'm very much sure, Please help me, this is the code which compiled and executed...
public class Ex2 {
public static void main (String args[]) {
int x = 4;
System.out.println("value is :"+((x>4) ?99.99:9));

}
}
the output is value is 9
i donno the reason..whether it varies from compiler to compiler..
Help me out...
thanks
Rajan
daryl olson
Ranch Hand

Joined: Aug 15, 2000
Posts: 36
I tried again and got 9.0.
As this is what is expected based I JLS, I don't know how you are getting 9
Anyone else wish to confirm this?
mehrar
Greenhorn

Joined: Aug 16, 2000
Posts: 19
Originally posted by daryl o:
I tried again and got 9.0.
As this is what is expected based I JLS, I don't know how you are getting 9
Anyone else wish to confirm this?

Me 2 got 9.0. I am using JDK 1.2.1
------------------
Raj


Raj
maha anna
Ranch Hand

Joined: Jan 31, 2000
Posts: 1467
Rajan Narayanan,
Can you tell us the platform and jdk version you are using?. Because as per JLS the 9 will be promoted to 9.0 double (binary promotion) and since the test condition is 'false', 9.0 will be printed.
regds
maha anna
thomas
Ranch Hand

Joined: May 26, 2002
Posts: 79
getting 9.0 (like maha anna explained)
JDK 1.2 on WINDOWS 98
thejus/mahesh
Greenhorn

Joined: Aug 21, 2000
Posts: 19
yes answer is 9.0 only we use win-nt and jdk1.2.1
Tushar Kansara
Ranch Hand

Joined: Aug 14, 2000
Posts: 38
I am not sure why is 9.0 being printed.
Are there any rules for Integer to be promoted to Float while being printed.
Regards
Tushar kansara
------------------
Rajan Narayanan
Greenhorn

Joined: Aug 07, 2000
Posts: 16
Hi all,
Thanx for all ur help !!! i guess i'm 'ving JDK 1.1, that's y i got 9 as output.
lemme try in higher version.
thanx
rajan.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Doubt