hi , I think 3)Math.round(-20.8)=-20 not -21 because it will round it to the next highest integer when fraction is 5 or >5.so -20 is greater than -21. If i am wrong please help me.
Kai Li I found this is really good question ? I don't understand when 20.5 is 21 why -20.5 is not -21. I tried the same with other languages I got it correct but JAVA ? Is any JAVA gurus are there to help us!!!
You don't need to be a Java expert to answer this question. All you have to do is to just look up the java.lang.Math API.
It says... public static long round(double a) Returns the closest long to the argument. The result is rounded to an integer by adding 1/2, taking the floor of the result, and casting the result to type long. In other words, the result is equal to the value of the expression: (long)Math.floor(a + 0.5d)