# How to calculate remainder in JAVA (%)

Show 40 post(s) from this thread on one page
Page 2 of 2 First 12
• 10-25-2010, 04:34 AM
pbrockway2
Code:

```26%6 = ??? 19  20  21  22  23  24  25  26 13  14  15  16  17  18 7  8  9  10  11  12 1  2  3  4  5  6 _  _  _  _  _  _ 1  2  3  4  5  6```

When you put 26 things into 6 stacks two things are left over. 26%6=2.

Quote:

is it 3 ?

Are you seriously saying that you can put 6 things into 26 stacks and end up with 3 left over?

Code:

```_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 1 2 3 4 5 6 7 8 9 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2                   0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6```

Forget decimal division and the number you get to the right of the decimal points. That has nothing to do with %.

And be careful about the order of the operands. 26%6 and 6%26 are different things.
• 10-25-2010, 04:51 AM
batista11b5
ok , I think i got it , so remainder is 9 ?

And if 5 % 26 and the remainder is 10 ? is it right ?

Thanks
• 10-25-2010, 06:09 AM
search4survival
i am sorry i am new to this and shouldn't recommend anything

but i think you have to solve this first using simple maths and then you can think in terms of a programming language.

If you cant solve a question on paper, likely chances you wont be able to do it in a program.
its simple multiplication..

if u have 7 % 2 ==> you do 2*3 =6 therefore remainder is 1.

if you have 11%5 ==>you just take the value of the right side (5) calculate it till you get below or equal the value on left side (11).

so in this case 5 * 3 = 15 so we are going above the value of left side.. therefore its 5*2 = 10

and remainder is again 1....
• 10-25-2010, 06:10 AM
joshdgreen
Quote:

Originally Posted by batista11b5
ok , I think i got it , so remainder is 9 ?

And if 5 % 26 and the remainder is 10 ? is it right ?

Thanks

??? *facepalm*
• 10-25-2010, 06:50 AM
DarrylBurke
This is beginning to look suspiciously like trolling. And if the OP's understanding is genuinely so flawed, s/he needs a math forum, not a Java forum.

db
• 10-25-2010, 07:39 AM
JosAH
Quote:

Originally Posted by batista11b5
ok , I think i got it , so remainder is 9 ?

And if 5 % 26 and the remainder is 10 ? is it right ?

On what planet? The Java modulo operator is defined as:

Code:

```int javaMod(int a, int b {   return a - b*(a/b); }```
where the '/' operator is integer division. Integer division is defined as:

Code:

```int javaDiv(int a, int b) {   return (a < b)?0:(1+javaDiv(a-b, b)); }```
for a >= 0 and b > 0.

kind regards,

Jos
Show 40 post(s) from this thread on one page
Page 2 of 2 First 12