Question
I need help with writing 3 Recursive methods. Number 1) /** This method displays a given character the specified number of times on one line.
I need help with writing 3 Recursive methods.
Number 1)
/** This method displays a given character the specified number of times on one line. For example, the call displayRowOfChacaters('+', 5); returns "+++++" Implement this method using recursion. @param toShow The character to display. @param n The number of times to display it; n>0. @return String representations of n toShow chars. */
public static String displayRowOfCharacters(char toShow, int n) {
}
Number 2)
/** * Recursively display an array backward starting at position n.
* E.g., displayBackwards(new Integer[]{1,2,3,4}, 2)
* would return "21".
*
* Implement this method using recursion.
*
* @param arr The array to display will have at least two elements.
* @param n The number of entries to be returned; 1<=n<=arr.length.
* @return String value of first n values of arr backwards.
*/
public static String displayBackwards(int[] arr, int n)
{
}
Number 3)
/**
* Recursive method that finds the second smallest object in an array of
* Comparable objects. E.g., getSecondSmallest(new Integer[]{-1,10,3,2},4)
* would return 2.
*
* @param arr An array of Comparable objects; arr.length>=2.
* @param len Length/size of arr array.
* @return Second smallest (Comparable) object in this array.
*/
public static > T getSecondSmallest(T[] arr, int len)
{
}
NOTE: NO DATA FIELDS CAN BE INTRODUCED AND USED and NO IMPORT STATEMENTS ARE ALLOWED
Also NO USAGE OF FULLY-QUALIFIED CLASS NAMES ARE ALLOWED
These three different methods should go in a class called
public final class RecursionProblems{
}
Thank you for your help!
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started