Results 1 to 2 of 2

Thread: Palindrome Test

  1. #1
    Ada
    Ada is offline Member
    Join Date
    May 2007
    Posts
    8
    Rep Power
    0

    Default Palindrome Test

    I am trying to write a program that repeatedly prompts a user for a positive integer number and tests whether the number is a palindrome. The program should convert the integer value given by the user into its reverse number. It should then check to see whether the reverse number equals to the original number.

    How can i do this?

  2. #2
    Hasan is offline Member
    Join Date
    May 2007
    Posts
    11
    Rep Power
    0

    Default

    It is quite easy to reverse a non negative number though:

    Java Code:
       public int reverse(int n) {
          int r;
          for (r= 0; n != 0; n/= 10) 
             r= 10*r+n%10;
          return r;
     }
    A number n is a palindrome if:

    n == reverse(n)

Similar Threads

  1. Shallow Copy Test
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-16-2008, 11:04 PM
  2. Array Fill Test
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:45 PM
  3. Array Search Test
    By Java Tip in forum java.lang
    Replies: 0
    Last Post: 04-14-2008, 08:45 PM
  4. Replies: 0
    Last Post: 04-05-2008, 12:38 AM
  5. DepUnit test framework
    By brianhks in forum Reviews / Advertising
    Replies: 0
    Last Post: 07-27-2007, 05:35 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •