This week's giveaway is in the Android forum. We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line! See this thread for details.

Answer is given as -5,6,-5,5. My doubt is the 3 rd output. Math.round(-5.49f)--- how come this is -5. As per my understanding it is -6. Could anyone please explain this. Its confusing me a lot.

round always rounds a float or a double to the nearest integer or a long respectively. If it is right in the middle like 5.5, it rounds to the nearest large integer. For the above example, -5.49 is closer to -5 than it is to -6. Hence , the output.

Vidyavathi, If you look the underlying implementation of round , it is nothing but adding 0.5f to the number and then perform floor on the result. In your case,

I know this round function is confusing sometimes, but if you know floor method correctly then you will never fail in getting answer for round function. Hope this helps ya. [ November 11, 2004: Message edited by: Jay Pawar ]

Cheers,<br />Jay<br /> <br />(SCJP 1.4)<br />Heights of great men were not achieved in one day, they were toiling day and night while their companions slept.