public class Algorithms { public static int reverseInt(int n) { return Integer.parseInt(new StringBuffer(String.valueOf(n)).reverse().toString()); } }
- public class Algorithms {
- public static int reverseInt(int n) {
int reversed = 0;while(n != 0){reversed = reversed * 10 + (n % 10);n /= 10;- return Integer.parseInt(new StringBuffer(String.valueOf(n)).reverse().toString());
- }
return reversed;}- }