Java经典习题25

/*
题目:一个5位数,判断它是不是回文数。即12321是回文数,个位与万位相同,十位与千位
*/

import java.util.*;

public class Class25 {

public static void main(String[] args) {
System.out.println("输入数字:");
Scanner sc = new Scanner(System.in);
long a = sc.nextLong();
String ss = Long.toString(a);
char ch[] = ss.toCharArray();
int cd = ch.length;
int cd1 = cd % 2;
int cd2;
int cd3;
boolean rs = false;
System.out.println("是不是回文数呢?");
if(cd1 == 1){
cd2 = cd1 + 1;
for(int i = 0; i <= cd2 - 1; i++){
if(ch[i] == ch[cd - i - 1]){
rs = true;
}else{
rs = false;
}
}
}
if(cd1 == 0){
cd3 = cd1;
for(int j = 0; j <= cd3; j++){
if(ch[j] == ch[cd - j - 1]){
rs = true;
}else{
rs = false;
}
}
}
System.out.println(rs);

}

}

猜你喜欢

转载自www.cnblogs.com/zhuozige/p/12358678.html