# Thread: How to calculate remainder in JAVA (%)

1. Moderator
Join Date
Feb 2009
Location
New Zealand
Posts
4,712
Rep Power
14
Java 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.

is it 3 ?

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

Java 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.

2. Member
Join Date
Oct 2010
Posts
23
Rep Power
0
ok , I think i got it , so remainder is 9 ?

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

Thanks

3. Member
Join Date
Apr 2010
Posts
22
Rep Power
0
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....

4. 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*

5. 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

6. 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:

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

Java Code:
```int javaDiv(int a, int b) {
}```
for a >= 0 and b > 0.

kind regards,

Jos

Page 2 of 2 First 12

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•