java 判断回文数字

 

//check whether the number is palindrome or not

/*
 * a number is said to be palindrome if, reverse of the number is same to 
 * that of real. for example, 121, 52025, 5885 etc..
 */
import java.util.Scanner;

public class Numbers {

    public static void main(String[] args) {
        int num, rev = 0;
        Scanner ip = new Scanner(System.in);
        System.out.print("Enter a number: ");
        num = ip.nextInt();
        int temp = num;
        while (num > 0) {
            int rem = num % 10;
            rev = (rev * 10) + rem;
            num = num / 10;
        }
        if (temp == rev)
            System.out.println("It is palindrome");
        else
            System.out.println("It is not a palindrome");
        ip.close();
    }
}



OUTPUT:
Enter a number: 12321
It is palindrome

 

posted @ 2020-01-03 09:42  anobscureretreat  阅读(688)  评论(0编辑  收藏  举报