AP® Computer Science A glossary
Remainder operator (%)
Also called: modulus, mod
Course: AP® Computer Science A Shows up in: Unit 1: Using Objects and Methods
The % operator: a % b gives the remainder when a is divided by b.
Appears in the course and exam description (CED): 1.3.C.4
17 % 5 is 2. Common uses: n % 2 is 0 for even numbers, and n % 10 gives the last digit. Negative first values and divisors of 0 or less are outside the course.
System.out.println(17 % 5);
System.out.println(347 % 10);
System.out.println(135 % 60);
Output:
2
7
15 Learn it properly, with a checkpoint 1.3 Expressions and Output