Loading...
Loading...
Loading...
A railway clerk reads ticket numbers backwards to check them. Read n and print its digits in reverse order as a number. Zeros at the end of n become leading zeros, which are not written: 1200 reversed is 21.
int.Example 1
Input
12345
Output
54321
The digits in reverse.
Example 2
Input
1200
Output
21
0021 is written as 21.
Try the problem first. Open one hint at a time.
Take the last digit with n % 10 and drop it with n / 10.
Build the answer as rev = rev * 10 + digit: each step shifts the answer left and adds the new digit.
Keep rev in a long.
Write your Java code, run it on the examples and submit it to hidden tests.
Solve in the editor