5 digit Palindrome

Java Question

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");
            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.


Default Text

Verified Answer?

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

by:Posted 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");
              System.out.println("it is not a palindrome");

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

This content is available to Experts Exchange members

See the answer now
with your Free 30 Day Trial

Get unlimited access to solutions & experts

  • 4,169,477 solved questions
  • 3,805 articles & videos
  • 15,413 tech experts

Get Access Now

Need a customized answer?
Ask your question for one-on-one assistance. We will email you when an expert has commented on your question.

We will never share this with anyone. Privacy Policy Terms of Use

Select topics

You may select up to five topics.


Related Articles

Related Questions

Experts Exchange powers the growth and success
of technology professionals worldwide.

  • Solve

    Experts Exchange is the tech professional’s trusted, on-demand resource for solving difficult problems, making informed decisions, and delivering excellent solutions.

  • Learn

    With unparalleled access to technical experts, verified real-world solutions, and diverse educational content, Experts Exchange enables personalized development of technology skills.

  • Network

    Experts Exchange gives you the professional exposure and valued relationships key to building the career you want.

Join the Network Today

See Plans and Pricing