Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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 }

} image text in transcribed

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 COMPLETE

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_2

Step: 3

blur-text-image_3

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

Securing SQL Server Protecting Your Database From Attackers

Authors: Denny Cherry

2nd Edition

1597499471, 978-1597499477

More Books

Students also viewed these Databases questions

Question

Compare levels of resolution in conflict outcomes?

Answered: 1 week ago

Question

Strategies for Managing Conflict Conflict Outcomes?

Answered: 1 week ago