回文串 例如 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;
}
}
结果: