Forums Register Login

using ==

+Pie Number of slices to send: Send
hi friends please go thru the following code snippets and clarify my doubt.


class comptest
{

public static void main(String rgs[])
{
float f=10;
double d=10;

if(f==d)
System.out.println(true);
}

}




public class comptest1
{
public static void main(String[] args)
{
double d = Integer.MAX_VALUE;
float f= Integer.MAX_VALUE;
if (f == d)
System.out.println("equal");
else
System.out.println(" not equal ");

}
}
the code of class comptest prints true while the class comptest1 doesnt.please clarify why as we are comparing float and double in both the cases.

regards
raja
+Pie Number of slices to send: Send
Have you tried



in comptest2? That might tell you something.
Why fit in when you were born to stand out? - Seuss. Tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 758 times.
Similar Threads
why it is false
About primitive promotion.
equals
Integer.MAX_VALUE != Integer.MAX_VALUE ???
Confusing outputs
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 29, 2024 04:46:03.