3

I am trying to write Java code to obtain the last digit of a long (i.e. the rightmost digit).

If I were trying to obtain the last element of a string, I would use the substring() method.

What is the alternative or equivalent way when getting the last digit of a long?

user3208200
  • 89
  • 1
  • 4

1 Answers1

14

You can do

long digit = Math.abs(number%10);
Denys Séguret
  • 372,613
  • 87
  • 782
  • 758