publicintreverse01(int x){//目标值,因为获取的目标值可能会超出题目中要求的范围,所以我们采用long类型接收long ans =0;//目标值不等于0,才能对其进行分解。while(x !=0){int end =0;//获得末尾的数字
end = x %10;//将数字降解,比如211,解析出1并除以10,则为21,进一步分解x.
x =(x - end)/10;//目标值=分解的数字*10+下一个分解的数字.
ans = ans *10+ end;}//根据题意进行判断超出范围则返回0;int MAX_VALUE =(int) Math.pow(2,31)-1;int MIN_VALUE =(int)(Math.pow(2,31)-1)*-1;if(ans > MAX_VALUE || ans < MIN_VALUE){return0;}return(int) ans;}