- public static int reversed(int n) {
- String str = String.valueOf(n);
- char[] digits = str.tocharArray();
- int i;
- for (i = digits.length - 1; i >= 0; i--) {
- if (digits[i] != '0')
- break;
- }
- char[] reversed = new char[i + 1];
- int j;
- for (j = 0; j <= i; j++) {
- reversed[j] = digits[i - j];
- }
- return Integer.parseInt(new String(reversed));
- }