java编写输入一个数判断是否是回文数,所谓回文数比如121,1221,6778776

package com.hao947;

import java.util.Scanner;

public class demo5 {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int x = 0;
		x = scanner.nextInt();
		System.out.println("请输入一个4-8位的数");

		int dig[] = new int[10];
		int n = 0;
		while (x != 0) {
			dig[n++] = x % 10;
			x /= 10;
		}
		int flag = 1;
		for (int i = 0; i < n / 2; i++) {
			if (dig[i] != dig[n - 1 - i]) {
				flag = 0;
				break;
			}
		}
		if (flag == 1)
			System.out.println("Yes\n");
		else {
			System.out.println("No\n");
		}
	}
}

java编写输入一个数判断是否是回文数,所谓回文数比如121,1221,6778776,布布扣,bubuko.com

java编写输入一个数判断是否是回文数,所谓回文数比如121,1221,6778776

上一篇:1小时学Python脚本


下一篇:史上最牛逼的javascript俄罗斯方块,63行代码搞定啊