你上面举的例子1234321 已经超过范围了
代码如下:
import java.util.Scanner;
/**
* @author young
* @Description: TODO
* @date 2016年5月31日下午5:52:11
*/
public class Test {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Please input the number: ");
int num = sc.nextInt();
if (num < 0 || num > 1000000) {
System.out.println("Input Error");
System.exit(0);
} else {
String word = String.valueOf(num);
int i = word.length();// 获取长度
int j = 0;
while (j <= (i / 2) - 1 && word.charAt(j) == word.charAt(i - j - 1))
j++;
if (j == i / 2)
System.out.println("palindrome number.");
else
System.out.println("not palindrome number.");
sc.close();
}
}
}
public static void main(String args[]){
Scanner in = new Scanner(System.in);
System.out.println("请输入一个0到1000000的数字:");
int input = in.nextInt();
if(input<0||input>1000000){
System.out.println("Input Error!");
return;
}
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("palindrome number");
else
System.out.println("not palindrome number");
}
public static boolean isPalindromeNew(int x) {
int sum = 0;
int temp = x;
while (temp > 0) {
sum = sum * 10 + temp % 10;
temp /= 10;
}
return sum == x;
}