数字反转

Posted dongma

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数字反转相关的知识,希望对你有一定的参考价值。

  public static void main(String[] args) {
       int i = 9876;
        int num = caleReverseNum(i);
        System.out.println(num);
    }

    /**
     * 时间复杂度为n的位数
     */
    static int caleReverseNum(int num) {
        int rev = 0;
        while (num != 0){
            rev = rev * 10 + num % 10;
            num /= 10;
        }
        return rev;
    }

 

以上是关于数字反转的主要内容,如果未能解决你的问题,请参考以下文章