CS110 Lab 16
More String Manipulation
- Write a Java method isPalindrome() that receives a String and returns true if the string is a palindrome.
- Write a Java method that receives a string parameter. Return a string where for every char in the original, there are three chars.
Sample Output:
tripleChar("AB") returns: "AAABBB"
tripleChar("hello") returns: "hhheeellllllooo"
-
Write a Java method that receives a string parameter and an int n.
Return a string made of n repetitions of the last n characters of the string.
You may assume that n is between 0 and the length of the string, inclusive.
Sample Output:
repeatEnd("Hello", 3) returns: "llollollo"
repeatEnd("Hello", 2) returns: "lolo"
repeatEnd("Hello", 1) returns: "o"
- Write a Java method that receives a string parameter.
Return the number of words ending in 'e' or 'a' (not case sensitive).
(Note: Character.isLetter(char) tests if a char is an alphabetic letter.)
Sample Output:
countAE("Every day is a fine and beautiful day.") returns: 2
countAE("I love a banana with my cornflakes.") returns: 3
-
Write a Java method that receives a string parameter.
Return the length of the largest "block" in the string. A block is a run of adjacent chars that are the same.
Sample Output:
maxBlock("hoopla") returns: 2
maxBlock("abbCCCddBBBxx") returns: 3
maxBlock("") returns: 0