• 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

Math Class

 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
To all SCJP aspirants,
Make a note of the RETURN values of floor(),ceil(),and round() methods.
floor() - returns a double value
ceil() - returns a double value
round() - returns int,long value.
So the following code returns

float f = -3.2f;
System.out.println(Math.floor(f));
System.out.println(Math.ceil(f));
System.out.println(Math.round(f));
the values
-3.0
-3.0
-3 // an int.

Chandra
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Chandra:
To all SCJP aspirants,
Make a note of the RETURN values of floor(),ceil(),and round() methods.
floor() - returns a double value
ceil() - returns a double value
round() - returns int,long value.
So the following code returns

float f = -3.2f;
System.out.println(Math.floor(f));
System.out.println(Math.ceil(f));
System.out.println(Math.round(f));
the values
-3.0
-3.0
-3 // an int.

Chandra


Hi Chandra,
I found the following results to be:-
-4.0
-3.0
-3
Consider the following:-
ceil(-9.01) gives -9.0
ceil(9.01) gives 10.0
ceil(-0.1) gives -0.0
ceil(0.1) gives 1.0
ceil(-100) gives -100.0
ceil(100) gives 100.0
round(-5.49) gives -5 //goes more positive
round(5.49) gives 5
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry for that. I wanted to convey that round() return -3 and not -3.0 (This is a tricky question in the Exam)
Thanks for the Correction,Rich
Chandra
 
We can fix it! We just need some baling wire, some WD-40, a bit of duct tape and this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic