Win a copy of Escape Velocity: Better Metrics for Agile Teams this week in the Agile and Other Processes forum!
  • 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

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
 
Did you ever grow anything in the garden of your mind? - Fred Rogers. Tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic