Practice with Remainder Operator

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
go to previous page   go to home page   hear noise   go to next page

If you exchange 372 pennies for dollar bills, how many bills do you get? How many pennies are left over?

Answer:

  • Number of dollar bills is 372 / 100 == 3
  • Left over pennies is 372 % 100 == 72

Practice with Remainder Operator

For positive numbers, INT % X means to fit as many X as you can into INT, and then the left over amount is the value of the expression. Try that with the following:

Expression ResultExpression Result
7 3 7 5
10 5 10 6
129 100 1999 100
17 2 18 2

QUESTION 16:

If X is odd, what is X%2?