자바 판단 답문 숫자

3027 단어
//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

좋은 웹페이지 즐겨찾기