Question
Recursive method for recognizing a palindrome in java. Your program should do the following by modifying the below code: mport java.util.Scanner; public class Lab6{ public
Recursive method for recognizing a palindrome in java.
Your program should do the following by modifying the below code:
mport java.util.Scanner;
public class Lab6{
public static void main(String[] args){ /******************************************************** Palindrome */ if (!isaPalindrome("satanoscillatemymetallicsonatas")) System.out.println("You have a bug in your code!"); else System.out.println("check for palidrome ok"); Scanner console = new Scanner(System.in); System.out.print("Input a string >"); String line = console.nextLine(); while (!line.equals("")){ if (isaPalindrome(line)) System.out.println(line+ "is a palindrome"); else System.out.println(line+ "is *not* a palindrome"); System.out.print("Input a string >"); line = console.nextLine(); } }
/** method to determine whether the specified string is a palindrome * @param expr string * @return true if the specified string is a palindrome, otherwise false. */ public static boolean isaPalindrome(String expr){ // TO COMPLETE }
}
1. prompts the user to input a string 2. recursively check if the string is a palindrome; 3. print out a message accordingly; until an empty string is input. The recursive method to check the palindrome must have the following signature: public static boolean isaPalindrome (String expr) . The String class contains methods to obtain the length of a string; obtain the char at a specified position of a string; obtain a substring of a string; check the latest java api to find details of the String class. To obtain the input, use the method nextLine of the Scanner class. import java.util.Scanner public class Lab6 public static void main(String[] args) if (!isaPalindrome ("satanoscillatemymetallicsonatas")) else Palindrome System.out.println("You have a bug in your code!"); System.out.println("check for palidrome ok"); Scanner console -new Scanner(System.in); System.out.print("Input a string >"); String line -console.nextLine); while (!line.equals(""))I if (isaPalindrome(line)) System.out.println(line+ "is a palindrome"); else System.out.println(line "is not* a palindrome"); System.out.print("Input a string >"); line -console.nextLine () /kok method to determine whether the specified string is a palindrome k @param expr string k @return true if the specified string is a palindrome, otherwise false public static boolean isaPalindrome(String expr) ITO COMPLETEStep 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