• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Round Q

 
Ranch Hand
Posts: 132
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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!
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
0.51 + 0.5 = 1.01
 
Wait for it ... wait .... wait .... NOW! Pafiffle! A perfect tiny ad!
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic