Monday, May 12, 2014

Write a program to check number is Palindrome or not / Write a program to reverse a number.

import java.util.Scanner;

class Palindrome{
    public static void main(String[] args){
        Scanner in = new Scanner(System.in);
        System.out.println("enter a number");
        int n = in.nextInt();
        int a = n;
        int palindrome =0;
        int r = 0;
        while(n>0){
            r = n%10;
            n = n/10;
            palindrome = palindrome*10 + r;
        }
        System.out.println("Reverse of the entered num is: "+palindrome);
        if(palindrome==a){
            System.out.println(a+" number is palindrome.");
        }else{
            System.out.println(a+" number is not palindrome.");
        }
    }
}

No comments:

Post a Comment