Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Design And Relational Theory Normal Forms And All That Jazz

Authors: Chris Date

1st Edition

1449328016, 978-1449328016

More Books

Students also viewed these Databases questions

Question

What is Change Control and how does it operate?

Answered: 1 week ago

Question

How do Data Requirements relate to Functional Requirements?

Answered: 1 week ago