Question
Consider the following method. What is the result of mystery(5)? (5 points) public static int mystery(int n) { if (n >= 3) { return mystery(n
Consider the following method. What is the result of mystery(5)? (5 points)
public static int mystery(int n) { if (n >= 3) { return mystery(n 1) + 2; }
return n + 1; }
Question 1 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Question 2 (5 points)
Consider the following method. What is the value of mystery(2)? (5 points)
public static void mystery(int n) { if(n >= 10) { System.out.print(n + " "); } else { mystery(n + 2); } }
Question 2 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Question 3 (5 points)
Consider the following method. What is the value of recur("COMPUTER")? (5 points)
public static void recur(String str) { int len = str.length(); String temp = " ; if(len > 1) { temp = str.substring(1, len 1); recur(temp); } System.out.println(temp); }
Question 3 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Question 4 (5 points)
Consider the following method. What is the value of recur("mouse", 3)? (5 points)
public static String recur(String str, int n) { if(n >= str.length()) { return str; }
return str + recur(str.substring(n), n); }
Question 4 options:
|
| ||
|
| ||
|
| ||
|
| ||
|
|
Question 5 (10 points)
For the recursive method below, list the base case and the recursive statement, then show your work for solving a call to the recur() method using any parameter value 10 or greater. (10 points)
public static int recur(int n) { if(n < 3) { return 2; } else { return recur(n / 3) + 1; } }
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