
-----------------------------------
MysticVegeta
Fri May 06, 2005 6:00 pm

Mod (remainder)
-----------------------------------
Is there a command for Mod?
like 9 mod 2 = 1
9 - (2*4)

In Turing its simple 
put 9 mod 2

How about java?

Also, What is the round, ceil and floor commands?

-----------------------------------
JackTruong
Fri May 06, 2005 6:20 pm


-----------------------------------
The modulus command is the % symbol.
int mod = 9 % 2;
// output is 1

Round rounds the number to the nearest integer value, up or down, depending on it's decimal value. You might have picked this concept up in Math.

Floor automatically rounds the number down, if it was 8.999999999999 floored, it would be 8.

Ceil automatically rounds the number up, if it was 8.0000000000000001, then it would be 9.

Think floor, the ground, the down, and ceil, the ceiling, the up.

-----------------------------------
Hikaru79
Fri May 06, 2005 6:53 pm


-----------------------------------
The modulus command is the % symbol.
int mod = 9 % 2;
// output is 1

Round rounds the number to the nearest integer value, up or down, depending on it's decimal value. You might have picked this concept up in Math.

Floor automatically rounds the number down, if it was 8.999999999999 floored, it would be 8.

Ceil automatically rounds the number up, if it was 8.0000000000000001, then it would be 9.

Think floor, the ground, the down, and ceil, the ceiling, the up.
They function in the same way as in Turing -- I think his question was how to USE these methods.
MysticVegeta, they are all static methods of the Math class. So, you can do it like this:
int four = Math.round(4.03);
int seven = Math.floor(7.999);
int nine = Math.ceil(8.00001);

Because Math is part of java.lang, which is imported by default, you don't need to import anything to use these. Enjoy!

-----------------------------------
MysticVegeta
Fri May 06, 2005 8:42 pm


-----------------------------------
Thanks, they work fine! :)

-----------------------------------
JackTruong
Fri May 06, 2005 8:56 pm


-----------------------------------
Ah, I misinterpreted the question.
