What will happen if you invoke the following method? B is the answer but why? ------------- 1: public void check() 2: { 3: System.out.println(Math.min(-0.0,+0.0)); 4: System.out.println(Math.max(-0.0,+0.0)); 5: System.out.println(Math.min(-0.0,+0.0) == Math.max(0.0,+0.0)); 6: }
A) prints -0.0, +0.0 and false. B) prints -0.0, +0.0 and true. C) prints 0.0, 0.0 and false. D) prints 0.0, 0.0 and true.
Zero is signed and hence negative zero is less than positive zero. However, for equality purposes( ie == ) they are equal!!. Strange as it may seem, this is one of my favourite gotcha! 's Ajith
Open Group Certified Distinguished IT Architect. Open Group Certified Master IT Architect. Sun Certified Architect (SCEA).