Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Mod (remainder)
Index -> Programming, Java -> Java Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
MysticVegeta




PostPosted: Fri May 06, 2005 6:00 pm   Post subject: 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?
Sponsor
Sponsor
Sponsor
sponsor
JackTruong




PostPosted: Fri May 06, 2005 6:20 pm   Post subject: (No subject)

The modulus command is the % symbol.
code:
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




PostPosted: Fri May 06, 2005 6:53 pm   Post subject: (No subject)

JackTruong wrote:
The modulus command is the % symbol.
code:
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:
Java:
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




PostPosted: Fri May 06, 2005 8:42 pm   Post subject: (No subject)

Thanks, they work fine! Smile
JackTruong




PostPosted: Fri May 06, 2005 8:56 pm   Post subject: (No subject)

Ah, I misinterpreted the question.
Display posts from previous:   
   Index -> Programming, Java -> Java Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 5 Posts ]
Jump to:   


Style:  
Search: