@@ -0,0 +1,1503 @@
+/**%0A *%09Reverse digits of an integer.%0A *%0A *%09Example1: x = 123, return 321%0A *%09Example2: x = -123, return -321%09%0A *%09%0A *%09Have you thought about this?%0A *%09Here are some good questions to ask before coding. Bonus points for you if you have already thought through this!%0A *%0A *%09If the integer's last digit is 0, what should the output be? ie, cases such as 10, 100.%0A *%0A *%09Did you notice that the reversed integer might overflow? Assume the input is a 32-bit integer, %0A *%09then the reverse of 1000000003 overflows. How should you handle such cases?%0A *%09%0A *%09For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.%0A *%0A *%09Author: matao%0A *%0A */%0A%0Apublic class ReverseInteger %7B%0A%09public static int reverse(int x) %7B%0A%09%09long result = 0;%0A%09%09while(x != 0) %7B%0A%09%09%09result = result * 10 + x %25 10;%0A%09%09%09x /= 10;%0A%09%09%7D        %0A%09%09if(result %3E Integer.MAX_VALUE %7C%7C result %3C Integer.MIN_VALUE) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%09%09return (int)result;%0A    %7D%0A%0A    public static int reverse2(int x) %7B%0A%09%09int result = 0;%0A%09%09while(x != 0) %7B%0A%09%09%09int tmp = result * 10 + x %25 10;%0A%09%09%09x /= 10;%0A%09%09%09if(tmp/10 != result) %7B   // overflow judge%0A%09%09%09%09return 0;%0A%09%09%09%7D%0A%09%09%09result = tmp;%0A%09%09%7D        %0A%09%09return result;%0A    %7D%0A%0A    public static void main(String%5B%5D args) %7B%0A    %09System.out.println(reverse(-123));%0A    %09System.out.println(reverse(-12345));%0A    %09System.out.println(reverse(1000000003));%0A%0A    %09System.out.println(reverse2(-123));%0A    %09System.out.println(reverse2(-12345));%0A    %09System.out.println(reverse2(1000000003));%0A    %7D%0A%7D

add Reverse Integer solution