Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I help with writing a pseudo code and uml diagram for the following code. Source Code: import java.util.Scanner; public class PalindromeDetector { public static void
I help with writing a pseudo code and uml diagram for the following code.
Source Code:
import java.util.Scanner; public class PalindromeDetector { public static void main(String args[]) { Scanner scanner= new Scanner(System.in); String userString =""; // get user input string do { System.out.println("Enter the string (enter end to quit): "); // read string userString = scanner.nextLine(); if(userString.equalsIgnoreCase("end")) { break; } // call method and check if the input string is palindrome if (palindromeCheck(userString.toLowerCase(), 0, userString.length() - 1)) { System.out.println("The input string is palindrome"); } else { System.out.println("The input string is not palindrome"); } }while(!userString.equalsIgnoreCase("end")); // close the scanner object scanner.close(); } // A recursive method to check string palindrome or not public static boolean palindromeCheck(String str, int startIndex, int endIndex) { // if there is only one character if (startIndex == endIndex) return true; // if the start and end characters different if ((str.charAt(startIndex)) != (str.charAt(endIndex))) return false; // if more than 2 characters check the mid if (startIndex < endIndex + 1) return palindromeCheck(str, startIndex + 1, endIndex - 1); return true; } }
Step 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