Showing posts with label Reverse a number or check number is palindrome or not. Show all posts
Showing posts with label Reverse a number or check number is palindrome or not. Show all posts

Tuesday, May 27, 2014

Reverse a number or check number is palindrome or not

import java.util.Scanner;

public class ReverseNumber {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        System.out.println("Enter a number which you want to reverse: ");
        int a = in.nextInt(), r=0, s=0, p=a;
       
        while(p!=0){
            r = p%10;
            p = p/10;
            s = s*10 + r;
        }
        if(s==a){
            System.out.println("number entered by user "+a+" is a palindrome.");
        }else
            System.out.println("number entered by user "+a+" is not a palindrome.");
    }
}