RSS Forums RSS
Please support our Java advertiser: Lunarpages Java Web Hosting

application can read palindrome number.

Join Date: Jul 2008
Posts: 10
Reputation: @bhi is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
@bhi @bhi is offline Offline
Newbie Poster

Re: application can read palindrome number.

  #3  
Jul 25th, 2008
Try this. It can be made a lot more efficient. Next time please put at least a psuedo code.

  1. import java.io.*;
  2. class Pal
  3. {
  4. public static void main(String args[]) throws IOException
  5. {
  6. int num,rev=0,temp;
  7. boolean flag=true;
  8. BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
  9. while(flag)
  10. {
  11. System.out.println("Enter a number:");
  12. num=br.readline();
  13. //To check if it is a 5 digit number
  14. if(num/10000>=1 && num/10000<10)
  15. flag=false;
  16. }
  17. temp=num;
  18. //Reversing the number
  19. while(num!=0)
  20. {
  21. rev=rev*10+num%10;
  22. num=num/10;
  23. }
  24. if(rev==temp)
  25. System.out.println("It is a palindrome");
  26. else
  27. System.out.println("Not palindrome");
  28. }
  29. }
Reply With Quote  
Forums | Blogs | Tutorials | Code Snippets | Whitepapers | RSS Feeds | Advertising
All times are GMT -4. The time now is 12:58 pm.
Newsletter Archive - Sitemap - Privacy Statement - Contact Us
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC