Practice Questions: Methods
Implement the toAsterisks method, which should return a
string that's the same length as the given one, but consisting only of
asterisks (*).
public static String toAsterisks(String password)
Implement the reverse method, which should take in a string
and return a string with those characters appearing in the reverse
order.
Implement the isPalindrome method, which should take in a
string and return true only if that string reads the same forward and
backward. Try implementing this method without reversing the given
string.
Implement the method change, which should take in a string of
the form "first last" or "last, first", and return the same string in
the opposite form. For example, change("Dave Feinberg")
should return "Feinberg, Dave", and change("Feinberg, Dave")
should return "Dave Feinberg".
Implement the method makeUppercase, which should take in an
array of characters and modify the contents of that array so that each
lower case letter is replaced with the equivalent upper case letter.
Implement the method findLetterFrequencies below, which takes
in a string s consisting only of upper case letters, and
returns an array of integers, whose first value corresponds to the
number of A's in s, whose second value corresponds to the
number of B's in s, and so on.
public static int[] findLetterFrequencies(String s)
Write a method isPrime that takes in an integer and returns
true if that number is prime (only divisible by itself and 1).
Write a method buildArray that takes in two
integers--count and value, and returns an array with
count copies of value. For example,
buildArray(5, 3) would return the array {3, 3, 3, 3, 3}.
Write a method called printRectangle, which takes in 2
parameters--the number of rows and the number of columns--and prints a
rectangle of asterisks (*) with those dimensions. For example,
printRectangle(3, 5) should print:
*****
*****
*****
Write a method called printTriangle, which takes in a number
and prints a triangle of asterisks (*) with that many rows. For
example, printTriangle(4) should print:
*
**
***
****