aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Round Q Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Round Q" Watch "Round Q" New topic
Author

Round Q

Nitin Bhagwat
Ranch Hand

Joined: Sep 09, 2004
Posts: 132
This is from Dan's example:
Section 8: Fundamental Classes in the java.lang Package / java.lang.Math / Exam 2

Question 8
Which of the following statements is true in terms of the value returned by the java.lang.Math.round method?

a. Rounds the argument to the nearest whole number. If the result is equally close to two whole numbers, then the even one is returned.
b. Rounds the argument to the nearest whole number. If the result is equally close to two whole numbers, then the odd one is returned.
c. Adds 0.5 to the argument and takes the floor of the result.
d. Adds 0.5 to the argument and takes the ceil of the result.
e. None of the above

Ans given is c.

I tried following code and dosen't work as per c.
Please suggesut, if i am wrong.

class t {
public static void main (String[] args) {
System.out.println(Math.round(.51));
// Added .5 to the argument and took floor of the result.

System.out.println(Math.floor(.56));

}}

Thank you in advance!


"Imagination is more important than knowledge. Knowledge is limited. Imagination encircles the world."
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
0.51 + 0.5 = 1.01


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Round Q