用java编写输入的整数判断是不是回文数

如题所述

Scanner in = new Scanner(System.in);
System.out.println("请输入一个整数N=:");
int input = in.nextInt();
int i = 0;
int sum = 0;
int record=input;
while(true){
i = input%10;
sum =sum*10+i;
input /= 10;
if(input==0) break;
}
if(sum==record)System.out.println("是回文");
else System.out.println("不是回文");
温馨提示:答案为网友推荐,仅供参考
第1个回答  2014-02-12
int i=123321; StringBuffer f = new StringBuffer("+i+"); int i1=integer.paserInt( f.reverse().tostring());if (i==i1){
sysout("i是回文数")
} else{
//不是

}--部分引号和代码简写,就是反过来与以前相等就行了,倒叙相等,或者for循环反转,采纳顶一个
第2个回答  2014-02-12
/*
问题域分析:

1 2 3 4 3 2 1 --- 数据源
0 1 2 3 4 5 6 --- 下标号

0 6
1 5
2 4

7/2 = 3 --- 结论
*/

/**
* 检测回文数
* @param src 要测试的数据
* @return 是回文数返回true, 不是返回false
*/
public boolean check(String src){
String n = "1234321";
int len = n.length() - 1;

for(int i=0; i<n.length()/2; i++){
if(n.charAt(i) != n.charAt(len - i))
return false;
}

return true
}


希望能帮助你!

第3个回答  2018-02-08
public static void main(String[] args) {
Scanner s = new Scanner(System.in);
System.out.println("请输入一个五位数:");
String a = s.next();
System.out.print("\n倒序输出:");
String b = a
//倒序a
StringBuilder sb = new StringBuilder(a);
a = sb.reverse().toString();
//倒序a
System.out.println(a);//输出倒序的a
if (a.equals(b)) {//比较b和a是否一样!!!
System.out.println("yes");
} else {
System.out.println("no");
}
}
第4个回答  2014-02-12
先收藏。再想办法。
相似回答