← Unit 1 · all exercises
Saved in this browser only

Last digit

Return the last digit of a positive whole number. For 4728 that is 8. Dividing by 10 and taking the remainder gets you there.

int lastDigit(int n)

Solution.java
Loading editor…
Results

Examples

  • lastDigit(4728) → 8
  • lastDigit(5) → 5

There are also 3 hidden tests you can't see. Solve the problem, not the examples.