PDA

View Full Version : how to check if a number is divisible by another in java?



papermoon
July 30th, 2008, 08:17 PM
for eg. how could i check 9 and 2 to see if 2 can go into 9 without leaving a remainder?

tamoneya
July 30th, 2008, 08:22 PM
use the modulo or remainder operator: "%"
If it equals zero then they are divisible.

a%b == 0

papermoon
July 30th, 2008, 08:36 PM
ahh thanks alot. i did not know that operator existed! I'm now starting java as you can see...

tamoneya
July 30th, 2008, 08:40 PM
ahh thanks alot. i did not know that operator existed! I'm now starting java as you can see...

it exists in almost every modern programming language.

papermoon
July 30th, 2008, 10:06 PM
im now starting programming too LOL