Tuesday, August 31, 2010

Article | Java To Check Whether A Number is Pallindrome Or Not

To Check Whether A Number is Pallindrome Or Not



  1. import java.io.*;


  2. public class Palindrome {

  3. public static void main(String [] args){

  4. try{

  5. BufferedReader object = new BufferedReader(

  6. new InputStreamReader(System.in));

  7. System.out.println("Enter a number");

  8. int num= Integer.parseInt(object.readLine());

  9. int n = numb;

  10. int rev=0;

  11. System.out.println("The Number is : ");

  12. System.out.println(" "+ numb);

  13. for (int i=0; i<=num; i++){

  14. int r=numb%10;

  15. numb=numb/10;

  16. rev=rev*10+r;

  17. i=0;

  18. }

  19. System.out.println("Output after reversing: "+ " ");

  20. System.out.println(" "+ rev);

  21. if(n == rev){

  22. System.out.print("This Number is Palindrome!");

  23. }

  24. else{

  25. System.out.println("This Number is not palindrome!");

  26. }

  27. }

  28. catch(Exception e){

  29. System.out.println("Unknown Number!");

  30. }

  31. }

  32. }

Loading...

Comments :

0 comments to “ Java To Check Whether A Number is Pallindrome Or Not ”

Top Views

BloggerTipsTemplates

CHICKLETS

Enter your email address:

Delivered by FeedBurner

Followers