Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Like in Exercise 4 , your task is to develop a method called isPalindrome ( ) that takes a string as a parameter. If the

Like in Exercise 4, your task is to develop a method called isPalindrome() that takes a string as a parameter. If the string is a palindrome (a word that is spelled the same forward and backward), then the method will return a boolean of true. If the string is not a palindrome, then false is returned. The difference between this exercise and Exercise 4, however, is that you will need to use a helper method called reverse() within isPalindrome(). The reverse() method takes a string as a parameter and reverses it. Then the reversed string is returned.
Remember that capitalization matters. For example, "Level" would not be considered a palindrome because uppercase "L" and lowercase "l" are not the same.
Existing Code:
import java.util.*;
public class Exercise5{
public static String reverse(String x){
String y ="";
for (int i = x.length()-1; i >=0; i--){
y += x.charAt(i);
}
return y;
}
//add code below this line
//add code above this line
public static void main(String args[]){
String x = args[0];
System.out.println(isPalindrome(x));
}
}
Hint
Consider creating a new empty string and populating it with characters of the specified string in reverse order. Then check the two strings for equality. Remember that the method should return a boolean, therefore, you should declare a boolean variable and have that boolean change based on certain conditions. Then return that variable.
Requirements
You should not make any changes to the code that already exists. If you accidentally delete any existing code, you can copy and paste the entire program from above.
You must include the helper method reverse() within your isPalindrome() method; otherwise, you will not receive credit for your work!
1. The button below will compile and test the code with "Level"
Expected result : false
2. The button below will compile and test the code with "anna"
Expected output : true
3. The button below will compile and test the code with "022220"
Expected result : false
There is an exisinting question but it print out true for case 1 "Level"
it should be false
The rest of the case works fine . The code is in Java
Thank you

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

More Books

Students also viewed these Databases questions

Question

Is conflict always unhealthy? Why or why not? (Objective 4)

Answered: 1 week ago