刷题小能手之数组篇(3)
package arrayAlgorithm;
public class IntegerFlip {
public static int reverse(int x) {
int rev = 0;
System.out.println(-Math.pow(2,31));
System.out.println(Math.pow(2,31)-1);
if(x<-Math.pow(2,31)||x>Math.pow(2, 31)-1){
return 0;
}
if(x==0){
return 0;
}
if(x>0) {
String str = String.valueOf(x);
System.out.println("str:" + str);
int len = str.length();
int n = len - 1;
while (x != 0) {
int num = x % 10;
rev += num * Math.pow(10, n);
n--;
x /= 10;
}
return rev;
}else{
x = -x;
String str = String.valueOf(x);
System.out.println("str:" + str);
int len = str.length();
int n = len - 1;
while (x != 0) {
int num = x % 10;
rev += num * Math.pow(10, n);
n--;
x /= 10;
}
return -rev;
}
}
public static void main(String[] args) {
System.out.println(IntegerFlip.reverse(1534236469));
}
}