Question

Problem 1. A palindrome is a sequence of characters that reads the same backward as forward....

Problem 1. A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

Problem 2. Modify the program to determine whether a seven-digit number is a palindrome. Before modifying, rename the files to Palindrome2.java and Palindrome2Test.java as file names.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

As HOMEWORKLIB answer guidlines. If there are multiple questions then solve only one. I have solved the first one. Let me know if you have any doubts about it.


import java.util.*;

public class Palindrome
{
    public static void main(String args[]) throws Exception
    {
        Scanner s = new Scanner(System.in);
        System.out.print("Enter a 5-digit integer: ");
        String n=s.nextLine();
        if(n.length()!=5)
        {
            System.out.println("Number is not five digits long.");
            return ;
        }
        for(int i=0;i<2;i++)
            if(n.charAt(i)!=n.charAt(4-i))
            {
                System.out.println("Not a palindrome");
                return;
            }
        System.out.println("Palindrome");

    }
}

Add a comment
Know the answer?
Add Answer to:
Problem 1. A palindrome is a sequence of characters that reads the same backward as forward....
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • A palindrome is a sequence of characters that reads the same backward as forward. For example,...

    A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it's a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • JAVA: 4.31 (Palindromes) A palindrome is a sequence of characters that reads the same backward as...

    JAVA: 4.31 (Palindromes) A palindrome is a sequence of characters that reads the same backward as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554 and 11611. Write an application that reads in a five-digit integer and determines whether it’s a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value.

  • A palindrome is a sequence of characters that reads the same backwards as forward. For example,...

    A palindrome is a sequence of characters that reads the same backwards as forward. For example, each of the following five-digit integers is a palindrome: 12321, 55555, 45554, and 11611. Create an application that accepts a five-digit integer and determines whether it's a palindrome. Assume the user will enter only five digits, and never enter 0 as the first digit. I need the answer in visual studios please.

  • A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g.,...

    A palindrome is a word, phrase, or sequence that reads the same backward as forward, e.g., madam or nurses run. In this program, ask the user to input some text and print out whether or not that text is a palindrome. Create the Boolean method isPalindrome which determines if a String is a palindrome, which means it is the same forwards and backwards. It should return a boolean of whether or not it was a palindrome. Create the method reverse...

  • palindrome is a string that reads the same both forward and backward. C++ For example, the...

    palindrome is a string that reads the same both forward and backward. C++ For example, the string "madam" is a palindrome. Write a program that uses a recursive function to check whether a string is a palindrome. Your program must contain a value-returning recursive function that returns true if the string is a palindrome and false otherwise. Do not use any global variables; use the appropriate parameters.

  • C++ A palindrome is a string that reads the same backward as forward. For example, the...

    C++ A palindrome is a string that reads the same backward as forward. For example, the words mom, dad, madam and radar are all palindromes. Write a class Pstring that is derived from the STL string class. The Pstring class adds a member functionbool isPalindrome( )that determines whether the string is a palindrome. Include a constructor that takes an STL string object as parameter and passes it to the string base class constructor. Test your class by having a main...

  • please explain the answer A sequence of characters is called a palindrome if it reads the...

    please explain the answer A sequence of characters is called a palindrome if it reads the same way forward or backward. For example, 59AA95 is a six-character palindrome, and 59A95 is a five-character palindrome. Some other instances of palindromes: U NU, LON NOL, MALAYALAM, NOW ON, PUT UP, TOO HOT TO HOOT, NEVER ODD OR EVEN, ABLE WAS I ERE I SAW ELBA, and POOR DAN IS IN A DROOP. Find the number of nine-character palindromes that can be formed...

  • Write an application in java that reads in a five-digit integer and determines whether it is...

    Write an application in java that reads in a five-digit integer and determines whether it is a palindrome. If the number is not five digits long, display an error message and allow the user to enter a new value. Tips: 1. Determine the number of digits in the value input by the user , i.e. prompt the user to enter the number of digits of the number. Use a while loop to determine whether the user input contains the proper...

  • A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here...

    A palindrome is any word, phrase, or sentence that reads the same forward and backward. Here are some well-known palindromes: Able was I, ere I saw Elba A man, a plan, a canal, Panama Desserts, I stressed Kayak Write a program that determine whether an input string is a palindrome or not. Input: The program should prompt the user "Please enter a string to test for palindrome or type QUIT to exit: " and then wait for the user input....

  • A Palindrome is a string that is spelled the same way forward and backward (example: radar)....

    A Palindrome is a string that is spelled the same way forward and backward (example: radar). Write a Java program that asks the user to input a string and tests whether the string is a Palindrome or not. Display the message: "The string is a Palindrome" if it is, or "The string is NOT a Palindrome" if it is not. Assume that the user will enter a string without any spaces. The string can be any length. The String can...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT