Question
Exercise 2 Description A palindrome is a string that reads the same forwards as well as backwards. There can be numerical palindromes like 1331 or
Exercise 2 Description
A palindrome is a string that reads the same forwards as well as backwards. There can be numerical palindromes like "1331" or words that are palindromes like "racecar". In this exercise you will write a program that can test for simple palindromes. Your code should prompt the user for a string and then use a loopto test whether the string is character-by-character the same forwards as it is backwards and report the result to the user. Your code should keep asking for strings to test until the user responds with an empty string. In the ClosedLab06 folder, create a new Java program named Lab06b.java for this problem.
Exercise 2 Sample Output
This is a sample transcript of what your program should do. Enter a string: 1331 1331 is a palindrome. Enter a string: racecar racecar is a palindrome. Enter a string: blue blue is NOT a palindrome. Enter a string: Empty line read - Goodbye! You are not required to worry about case, spacing, punctuation or other issues. Your code should only check to see that the strings are exactly the same forwards as they are backwards: Enter a string: Racecar Racecar is NOT a palindrome Enter a string: RACECAR RACECAR is a palindrome. Enter a string: A man, a plan, a canal, Panama. A man, a plan, a canal, Panama. is NOT a palindrome. Enter a string: y123321y y123321y is a palindrome. Enter a string: Empty line read - Goodbye! NOTE: You MUST use a nested loop for this assingment. There are other ways to solve this problem, but for this assignment you must have a loop nested inside another loop. Thing about using the outer loop to read the String and the inner loop to test for the palindrome. NOTE 2: For this assignment you need to test whether or not a String is empty (a blank line). There are a few different ways that you can perform this check. One that will NOT work is to use the following if condition: if (myString == "") { /* do something if the string is empty */ } One way to solve this is to think about what having an empty line means. What's the length of an empty line? Another way to solve this one is to use the String equals() method instead of the == operator.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started