算法 回文数 ?

回文串  例如   123456  输出 654321

----算法

字符串反转?

package com.fandong.algorithm;


import org.apache.commons.lang3.StringUtils;

public class PalindromeString {
    public static void main(String[] args) {
        /**
         * 字符串反转
         */

        String  palindrome ="123456";
        String reverse = StringUtils.reverse(palindrome);
        System.out.println(reverse);

        /**
         * 不转字符串求
         */

        int re= getReverse(123456);
        System.out.println(re);
    }

    private  static  int getReverse(int sc){
        int result =0;
        while(sc != 0){
            int b = sc %10;
            result = result*10 +b;
            sc =sc/10;
        }
        return result;
    }
}

结果:

发布了61 篇原创文章 · 获赞 1 · 访问量 670

猜你喜欢

转载自blog.csdn.net/u012842247/article/details/103411789