Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Step: 3

blur-text-image

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

Financial management theory and practice

Authors: Eugene F. Brigham and Michael C. Ehrhardt

12th Edition

978-0030243998, 30243998, 324422695, 978-0324422696

Students also viewed these Programming questions

Question

Write a cryptogram for the message using the matrix

Answered: 1 week ago