Question: Palindrome Description Method Signature public static boolean isPalindrome(String input) Return true if input is a palindrome. A palindrome is a sequence of letters that is

Palindrome Description

Method Signature

public static boolean isPalindrome(String input)

Return true if input is a palindrome. A palindrome is a sequence of letters that is mirrored at its center. Examples: abba, acttca, aca, a. Each input line should contain a string to be tested; spaces are considered part of the string.

  • Base case 1:The length of the string is 0 or 1; both qualify as a palindrome; return true.
  • Base case 2:The first and last characters of the string do not match; this string is not a palindrome; return false.
  • Recursion case: The first and last characters of the string are equal; return the result of calling palindrome with the string after removing the first and last characters.

CountLetter Description

Method Signature

public static int countLetter( String input, char letter )

Return the number of occurrences of the character "letter" in the string "input".

  • Base case 1: The length of the string is 0; there are no characters left in the string that match theletter parameter; return 0.
  • Recursion case: If the first character doesn't match the parameterletter, return the result of calling countLetter on the rest of the string; if it does match, return 1 + the result of calling countLetter on the rest of the string.

MaxValue Description

Method Signature

public static int maxValue( int[] list, int n )

Find the max value in the array list[0,...,n-1]; n is the number of elements in the portion of the array being tested.

Hint:Math.max() is useful here

  • Base case: n = 1; the only element of the array must be the max, so return it.

Recursion case: For n > 1, return the larger of the "last" element of (this portion of) the array and the maxValue of everything before it in the array.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!