Judge the number of palindrome Java

topic:

A 5-digit number to determine if it is a palindrome. That is, 12321 is the number of palindrome, the ones place is the same as the ten thousand place, and the ten place is the same as the thousand place.

import java.util.*;
public class palindromeNumber {
    
    
	public static void main(String[] args) {
    
     
		Scanner s = new Scanner(System.in);
		boolean is =true;
		System.out.print("请输入一个正整数:");
		long a = s.nextLong();
		String ss = Long.toString(a);
		char[] ch = ss.toCharArray();
		int j=ch.length;
		for(int i=0; i<j/2; i++) {
    
    
			if(ch[i]!=ch[j-i-1]){
    
    
				is=false;
			}
		}
		if(is==true){
    
    
			System.out.println("这是一个回文数");
		}else {
    
    
			System.out.println("这不是一个回文数");
		}
	}
}

Guess you like

Origin blog.csdn.net/p715306030/article/details/113971562