Question
complet one line code 1 Complete the following recursive implementation of the max method. For input 5 2 6 7 9 1 3 2 11
complet one line code
1 Complete the following recursive implementation of the max method. For input
5 2 6 7 9 1 3 2 11 15 29 21 13
public class Test {
public static void main(String[] args) { Scanner stdin = new Scanner(System.in);
int[] vals = new int[30]; int cnt = 0;
while (stdin.hasNextInt()) { vals[cnt++] = stdin.nextInt(); }
System.out.println(max(vals, cnt - 1)); stdin.close(); }
public static int max(int[] vals, int end) {
int res; // your code starts here
// your code ends here
System.out.println(res); return res; }
}
2. Complete the following recursive implementation of the longest to find the longest string in an array. For input
All the pppproposals have been loaded into BB for your review. Let me know if you have questions.
public class Test {
public static void main(String[] args) { Scanner stdin = new Scanner(System.in);
String[] vals = new String[30]; int cnt = 0;
while (stdin.hasNext()) { vals[cnt++] = stdin.next(); }
System.out.println(longest(vals, cnt - 1)); stdin.close(); }
public static String longest(String[] vals, int end) {
String res; // your code starts here
// your code ends here
System.out.println(res); return res; }
}
3. Complete the following recursive implementation of the factorial method. Pay attention to your base case, your program should output
1 1 1 3 2 1 1 2 6 6 6 5 4 3 2 1 1 2 6 24 120 720 720
public class Test {
public static void main(String[] args) { System.out.println(factorial(1)); System.out.println(factorial(3)); System.out.println(factorial(6)); }
public static int factorial(int n) { System.out.println(n);
int res; // your code starts here
// your code ends here
System.out.println(res); return res; }
}
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