Multiple choice

If x is an integer > 10, how would you print the ten's digit?

  1. x / 10 % 10

  2. x % 10

  3. x / 10

  4. x % 10 * 10

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

Dividing an integer by 10 shifts the decimal point one place to the left, removing the ones digit (for example, 123 / 10 = 12). Taking the remainder modulo 10 (% 10) then extracts the new rightmost digit, which is the original tens digit (for example, 12 % 10 = 2).