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 30 '16

Modulo is the remainder from integer division.

4 / 3 = 1 r 1

4 % 3 = 1

1

u/[deleted] Oct 30 '16

What's a remainder ? English isn't my native lang.

2

u/[deleted] Oct 30 '16

It's the part that's left.

Consider that 4 / 3 = 1 r 1 and 4 -3 = 1.

Have you done the assigned reading?

-2

u/[deleted] Oct 30 '16

assigned reading

What's that

Didn't understand >Consider that 4 / 3 = 1 r 1 and 4 -3 = 1.

1

u/Rosydoodles Oct 30 '16

3*1 = 3, +1 = 4.

Therefore if you divide 4 by 3, you get one with a remainder (what you added above) of 1. The remainder is the result of modulo.

Assigned reading is the script from the class, powerpoint slides, or pages/chapters from the book the professor recommends.

1

u/[deleted] Oct 30 '16

It is when you are dealing with less than whole numbers, specifically by division. 4/3 = 1, because 4 divided by 3 goes in once (3), and has a remainder of 1 (which would be .25 decimally, or 1/4 fractionally).