Write the following RECURSIVE methods (non-recursive methods will receive no credit!): Remember: the basic process for creating
Fantastic news! We've Found the answer you've been seeking!
Question:
Write the following RECURSIVE methods (non-recursive methods will receive no credit!):
Remember: the basic process for creating a recursive method is to first determine the base case and then build the method.
String reverseString(String s)
This method returns the string with the characters in reverse order. For example:
reverseString("FOX") returns "XOF"
String insertCommas(int num)
This method takes a positive integer parameter and returns a string representing that integer with commas in appropriate places. The method might be called as follows:
System.out.print(insertCommas(1000000)); //prints "1,000,000"
(Hint: recurse by repeated division and build the string by concatenating after each recursive call.)
Previous
Related Book For
Posted Date: