r/learnjava • • Oct 30 '16

What the HELL is a modulo?

I have a test tomorrow, in the test one of the questions will be to seperate a number from a 3 digit number, say I have 641, I need to know how to print out 6,4 and 1 seperately.

What the hell do I do ? The teacher is so bad I couldn't understand a word she said and neither did my class, we already complained about her but this isn't the issue, the issue is that I have no easy answers on the internet for what the modulo is.

Why does doing (n/100)%10; print out the hundred digit ? I have no idea how this works, please go easy on me.

0 Upvotes

31 comments sorted by

View all comments

1

u/[deleted] Oct 31 '16

(n/100)%10 gives you 6 in your example because (641/100) = 6. Remember, we're talking about integer division here. There are no decimals in integer division. Normally 641/100 would equal 6.41 but in integer division we use only whole numbers. So then you do 6/10 and keep only the remainder. 10 goes into 6 zero times with a remainder of 6. So 6 is your answer and that formula will always print out the digit of the hundred's place.