Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In JAVA: Please follow all rules listed below and have the code be originally yo

ID: 3788625 • Letter: I

Question

In JAVA: Please follow all rules listed below and have the code be originally yours as I know this is already on chegg publicly I need unique code, I also need the last two questions answered at the bottom. Also please comment code if you can it really helps me, and make sure it prints out the output like it does in the example dialog! Thanks so much in advance, please do not submit a written picture of an answer but a typed response.

Implement a program which uses a recursive method that determines if a string entered by the user is a palindrome. A string is palindrome if it is the same forward as it is backwards, such as “radar” or “Taco cat”.

Here are assumptions about the recursive method

The method should ignore all spaces

The method should also ignore case

Assume if a string is less than two characters or is null that it is a palindrome

Do not use any loops or iteration that is not recursive

Hints:

Recursive methods generally attempt to solve a smaller problem then return the results of those in order to solve the larger one.

To recursively solve this always look at the first character and the last character. Only if they are equal do you recursively call the method again, but pass in a new string with the first and last character removed from the given string.

Some useful string methods but all may not be used in the solution

toUppercase(): makes all characters uppercased

toLowercase(): makes all characters lowercased

charAt(index): returns a character at the specified index

trim(): returns a string with leading and trailing whitespace removed

substring(startIndex,endIndex): returns a string from the starting index (inclusive or is included) to the ending index (exclusive or is not included).

Example Dialog:

Enter a word and I will determine if it is a palindrome

Taco Cat

The word "Taco Cat" is a palindrome

Questions:

Using the recursive method, write out the string that is being processed at each step if the word “radar” was entered. Do the same for “Straw arts”.

Write some simple code using the iterative method (using loops) to solve this same problem.

Explanation / Answer

This is the Perfect Solution what you are looking for and I mentioned the solution with the comments.

import java.util.Scanner;

public class Hexagon{
   //My Method to check
public static boolean isPal(String s)
{ // remove the spaces in string and convert to lowercase
   s=s.replaceAll("\s+","").toLowerCase();
   // if length is 0 or 1 then String is palindrome
if(s.length() == 0 || s.length() == 1)
return true;
if(s.charAt(0) == s.charAt(s.length()-1))
/* check for first and last char of String:
* if they are same then do the same thing for a substring
* with first and last char removed. and carry on this
* until you string completes or condition fails
* Function calling itself: Recursion
*/
return isPal(s.substring(1, s.length()-1));

/* If program control reaches to this statement it means
* the String is not palindrome hence return false.
*/
return false;
}

public static void main(String[]args)
{
   //For capturing user input
Scanner scanner = new Scanner(System.in);
System.out.println("Enter the String for check:");
String string = scanner.nextLine();
/* If function returns true then the string is
* palindrome else not
*/
if(isPal(string))
System.out.println(string + " is a palindrome");
else
System.out.println(string + " is not a palindrome");
}
}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote