Hi Ragu,
The problem comes from the argument conversion in the compare method invocation. I've added some lines in the code to show you why it is so...
public class
Test {
static double d;
static float f;
public static void main(String args[])
{
compare(Long.MAX_VALUE, Long.MAX_VALUE );
compare(Integer.MAX_VALUE, Integer.MAX_VALUE );
compare(Character.MAX_VALUE, Character.MAX_VALUE);
compare(Short.MAX_VALUE, Short.MAX_VALUE );
compare(Byte.MAX_VALUE, Byte.MAX_VALUE );
}
static void compare(double d, float f)
{
System.out.println("double="+d);
System.out.println("float="+f);
if (f == d) System.out.println(" equal" );
else System.out.println(" unequal");
}
}
Output:
double=9.223372036854776E18
float=9.223372E18
equal
double=2.147483647E9
float=2.14748365E9
unequal
double=65535.0
float=65535.0
equal
double=32767.0
float=32767.0
equal
double=127.0
float=127.0
equal
Now you can see that MAX_INT converted to Double and MAX_INT converted to Float are not quite the same...
Hope that helps,
Val