【王道JAVA】【程序 25 求回文数】

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

import java.util.Scanner;

public class WangDao {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		System.out.print("Input your number: ");
		int n = scan.nextInt();
		int[] arr = new int[100];
		int count = 0;
		boolean flag = true;
		
		while (n != 0) {
			arr[count++] = n % 10;
			n /= 10;
		}
		for (int i = 0, j = count-1; i < j; i++, j--) {
			if (arr[i] != arr[j]) {
				flag = false;
			}
		}
		if (flag) {
			System.out.println("This number is the palindrome number.");
		} else {
			System.out.println("This number is not the palindrome number.");
		}
		
	}
}

猜你喜欢

转载自blog.csdn.net/YelloJesse/article/details/89408838