翻转数字

反转数字

http://www.nowcoder.com/questionTerminal/1a3de8b83d12437aa05694b90e02f47a

翻转数字

对于溢出的判断在我看来只需要在最后进行是否溢出的提示

 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;
    }
全部评论

相关推荐

1 1 评论
分享
牛客网
牛客企业服务