Sunday, 8 January 2012

Polindrome Program

program to check whether number is palindrome or not
program to check whether number is palindrome or not,polindrom program in java with example in java,java program to know whether a number is polindrome or not,polindrom program,polindrome in java,java polindrom with program.

import java.io.*;

public class poli  {
      public static void main(String [] args){
          try{
            BufferedReader object = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("Enter number");
            int num= Integer.parseInt(object.readLine());
              int n = num;
              int rev=0;
              System.out.println("Number: ");
              System.out.println(" "+ num);
              for (int i=0; i<=num; i++){
                  int r = num%10;
                  num = num/10;
                  rev = rev*10+r;
                  i=0;
              }
              System.out.println("After reversing the number: "+ " ");
              System.out.println(" "+ rev);         
              if(n == rev){
                System.out.print("Number is palindrome!");
              }
              else{
                System.out.println("Number is not palindrome!");
              }
          }
          catch(Exception e){
              System.out.println("Out of range!");
          }
    }
}    


program to check whether number is  polindrom or not,polindrom program in java,polindrome program, the below is the output for that    


D:\javaprog>javac polindrome.java

D:\javaprog>java polindrome
Enter number
121
Number:
 121
After reversing the number
 121
Number is palindrome!
D:\javaprog>javac polindrome.jav

D:\javaprog>java polindrome
Enter number
567
Number:
 567
After reversing the number
 765
Number is not palindrome!

No comments:

Post a Comment