Quote:
Originally posted by: craddy
I have been told to use the modulus function aswell as division, but I have no clue!
|
Remember in elementary when you were first taught long division? Think of modulus as something like that.
Code:
Example: modulus1
___4_ Remainder 1
3 | 13
12
1
That division problem has a remainder of 1, because 4 goes into 13
evenly only 3 times, and it ends up with a decimal (.25) or a remainder of 1.
Ergo, 4567 % 10 = 7, as maniac01 told you. The answer is 7 because:
Code:
Example: modulus2
___456___ Remainder 7
10 | 4567
40
5
56
50
6
67
60
7
Hope this helped. Moduluses are quite simple to code, ontop of that. For instance.
Code:
Example: modulus3
public class modulusTest {
public static void main(String[] args) {
int mod = 4567 % 10;
System.out.println(mod);
//System.out.println(4567 % 10);
}
}