5 digit Palindrome

    Question by:
    On

    Topics:

    Does anyone have any feedback on how to write a program that inputs a 5-digit integer from the keyboard and prints if the input number is a palindrome or not.

    This is the program I wrote:

    import java.util.*;
     class Tester22
    {
          public static void main(String args[])
          {
          int palindrome number =0;
                int n1 = Integer.parseInt(number);
                Scanner input = new Scanner(System.in);
                System.out.println("Please input a 5-digit number);
                int given = input.nextInt();
                If(number >="Is a palindrome number");
                else
                If (number >="Is not a palindrome number");
                System.out.println(" number + palindrome");
                System.out.println("number += not a palindrome");
          }
    }
    The compilation left me with this result:'

    ';' expected')'                      line 6


      ')' expected                      line 10


    'else' without 'if'                 line  12


    I have tried everything to make this program compile.   I will keep at it!  While someone gives me a hand.



    Fred








    Good Question?
    0
     

    ?

    The member who asked this question verified this comment provided the solution that solved their problem.

    Accepted Solution on 2006-12-20 at 00:23:00ID: 18171973

    The easiest would be to turn the number into a string and check it with a reverse string.

    public static void main(String args[]) throws IOException
         {
              int palindrome_number=0;
              System.out.println("Please input a 5-digit number");
              BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
              String line = input.readLine();
              boolean palindrome = line.equalsIgnoreCase(new StringBuffer(line).reverse().toString());
              if (palindrome)
              {
                  System.out.println("it is a palindrome");
              }
              else
              {
                  System.out.println("it is not a palindrome");
              }
         }

    BTW this is the best place to start: http://java.sun.com/docs/books/tutorial/



    Top Expert Contributor

    Essential articles and videos from the Experts

    More valuable questions with Expert answers

    201511-LO-Qu-074

    Extend your technology team with the Experts Exchange community.

    — trusted by —

    Who answers my questions?Our community has technology experts around the world.

    CEHJ

    Expert in:

    • Java
    • Java EE
    • Editors IDEs
    • JSP
    • Programming

    dpearson

    Expert in:

    • Java
    • Java EE
    • Programming
    • Game Programming
    • JSP

    mccarl

    Expert in:

    • Java
    • Java EE
    • Programming
    • JSP
    • Algorithms

    Amitkumar Panchal

    Expert in:

    • Java
    • Java EE
    • JSP
    • Oracle Database

    ozo

    Expert in:

    • Perl
    • Math / Science
    • Regular Expressions
    • Shell Scripting
    • Algorithms

    Chris Luttrell

    Expert in:

    • MS SQL Server 2005
    • MS SQL Server 2008
    • MS SQL Server
    • SSRS
    • Query Syntax

    Prasenjit Das

    Jan Springer

    Expert in:

    • Routers
    • Cisco PIX/ASA
    • DNS
    • Linux
    • Networking

    mugojava

    Expert in:

    • Linux

    RELATED TOPICS view all topics

    1. Java EE
      (16,906)
    2. Editors IDEs
      (25,092)
    3. JSP
      (15,368)
    4. Programming
      (51,613)
    5. Programming Languages
      (19,577)
    6. Java App Servers
      (6,999)
    7. Web Servers
      (32,317)
    8. Web Languages/Standards
      (39,422)
    9. JavaScript
      (117,316)
    10. Oracle Database
      (77,135)