翻转数字
对于溢出的判断在我看来只需要在最后进行是否溢出的提示
public int reverse (int x){ // write code here int ans = 0; while (x != 0){ ans = ans*10+(x%10); x/=10; } if(ans<Integer.MIN_VALUE||ans>Integer.MAX_VALUE){ ans = 0; System.out.println("反转后数字溢出"); } return ans; }
对于溢出的判断在我看来只需要在最后进行是否溢出的提示
public int reverse (int x){ // write code here int ans = 0; while (x != 0){ ans = ans*10+(x%10); x/=10; } if(ans<Integer.MIN_VALUE||ans>Integer.MAX_VALUE){ ans = 0; System.out.println("反转后数字溢出"); } return ans; }