# Thread: I need help finding a remainder

1. Member Join Date
Sep 2012
Posts
68
Rep Power
0

## I need help finding a remainder

Hey guys im writing a program for my computer science class and its kicking my ass. The think im having a problem with is making it tell me what the remainder is im using the modulous *correctly i think* but it keeps being weird. Ill show you the code ive wrote so far

import java.util.Scanner;
public class Prog72a
Java Code:
```{
public static void main(String args[])
{
int a,b,c,d;
int e = 26;

Scanner aa = new Scanner(System.in);

System.out.println("imput the first two numbers");

a = aa.nextInt();

Scanner bb = new Scanner(System.in);
System.out.println("imput the second two numbers");
b = bb.nextInt();

Scanner cc = new Scanner(System.in);
System.out.println("imput the third two numbers");
c = cc.nextInt();

Scanner dd = new Scanner(System.in);
System.out.println("imput the fourth two numbers");
d = dd.nextInt();

int f = a + b + c + d % e;

System.out.println("The remainder is" + f);

}
}```
So at the point im at now it should tell me what the remainder is of the 4 two digit numbers i put in divided by 26 but when i do for some reason it will just add the 4 two digit numbers up and tell me what their sum is...unless i do "26 26 26 26" then it tells me the sum of the four 26's but it subtracts 26 so the number it shows me is 78. Please help guys, i really have no clue whats wrong, i think im using the modulous wrong.
Last edited by MrPosotive; 09-24-2012 at 06:49 AM.  Reply With Quote

2. Member Join Date
Jul 2012
Posts
9
Rep Power
0

## Re: I need help finding a remainder

You have to follow the rules of operator precedence when you are using arithmetic expressions. Here '%' is having a higher precedence than '+' hence the operation that will be first performed here is modulus and the result will be added with the other variables. Use the expression "(a+b+c+d)%d". This should solve your problem. Let me know if it doesn't  Reply With Quote

3. Member Join Date
Sep 2012
Posts
68
Rep Power
0

## Re: I need help finding a remainder

Thanks a lot, i feel dumb now.  Reply With Quote

#### Posting Permissions

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