Here are some tips you might need:
1) If you use / for arguments that will be integer, then your result will also be integer.
Example:
int x = 7/2; System.out.println(x);
output: 3 (not 3.5 )
So, to get rid of the last digit of an integer, you can simply divide this number by 10, for example
int x = 123; x = x/10; System.out.println(x);
Output: 12
2) Java also has a modulo operator that returns a reminder from the division, for example 7/2=3 and 1 will be a reminder. This % operator
Example
int x = 7; x = x % 5; System.out.println(x);
Output: 2 , because 7/5=1 (2 remains)
So, to get the last digit from an integer, you can just use % 10 as
int x = 123; int lastDigit = x%10; System.out.println(lastDigit);
Output: 3
Now try to combine this knowledge. Get the last digit of the number, add it to the amount, delete this last digit (repeat until there are more digits).
source share