Ok, I'm working on a project and I need to write a method that takes an input number, divides by three and then returns the number that is the closest mathematical integer above it. So a method that rounds up should be involved. I'm trying to test out the Math.ceil and Math.floor methods but I'm confused.
7 / 3 is 2.333~
So I don't understand why both
are returning 2.0. Shouldn't Math.ceil return 3.0? What am I missing please?
"When you divide an int value by another int value, you get an int value. The computer doesn't round... (it) chops off any remainder... If you need a decimal answer, make either (or both) of the numbers you're dividing double values." Barry Burd, Author, Beginning Programming with Java for Dummies
I believe this means you must change your numbers to decimals, then divide, then round.
Disclaimer: The author of this post makes no claims, implied or otherwise, as to her ability to understand anything but the simplest of answers. Further, the author of this post has no programming background whatsoever and has taken one Java Programming class which was 9 weeks long. She does want to learn, so please teach patiently.
Leroy J Brown
Joined: Dec 02, 2007
So can I cast the numbers some how like this...
or do I have to initialize them as variables such as