publicintreverse(int x){int res =0;boolean flag =false;if(x <= Math.pow(-2,31)|| x >= Math.pow(2,31)-1)return res;
StringBuilder builder =newStringBuilder();if(x <0){
flag =true;// builder.append("-");
x = Math.abs(x);}
String str = x+"";for(int i = str.length()-1; i >=0; i--){char c = str.charAt(i);if( c =='0'&& builder.length()<1)continue;
builder.append(c);}
String s =newString(builder);if(s.equals(""))
s =0+"";try{if(flag)return-Integer.parseInt(s);return Integer.parseInt(s);}catch(Exception e){// TODO: handle exceptionreturn0;}}
取余
publicintreverse(int x){long res =0;while(x !=0){
res = res *10+ x %10;
x /=10;}try{return(int)res == res ?(int)res:0;}catch(Exception e){return0;}}