zoukankan      html  css  js  c++  java
  • 1.整数反转

    1.如何反转

    public static int reverse(int x) {
           //用数学思维来看
            int rpc = 0;
            while (x != 0)
            {
                int newrpc = rpc*10 + x%10;//数学思维取反过程
                rpc = newrpc;
                if ((newrpc - x%10)/10 != rpc) {return 0;}//判断,不相等则说明溢出了
                x = x/10;
               
            }
            return rpc;
        }
    完整的反转整数
    long temp=0;
            while(x!=0){
                temp*=10;
                temp+=x%10;
                x/=10;
            }
    2.反转溢出问题
    (1)我觉得溢出这个最简单的解决办法就是捕获异常,返回0
    (2)2的31次方,Math.pow(2,31)
    (3)为了解决溢出问题,我们使用了long类型来存储结果,最后判断一次即可
  • 相关阅读:
    Daily Scrum
    Daily Scrum
    Daily Scrum
    Daily Scrum
    Daily Scrum
    bing背单词交互流程
    立会2015-11-23
    每日例会11.16
    每日立会2015-11-11
    单词挑战设计0.1
  • 原文地址:https://www.cnblogs.com/manmanchanglu/p/11413788.html
Copyright © 2011-2022 走看看