1. Consider the following method. What is the result of mystery(10)? (5 points) public static int mystery(int n) {

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

1. Consider the following method. What is the result of mystery(10)? (5 points) public static int mystery(int n) {

Post by answerhappygod »

1.
Consider the following method. What is the result
of mystery(10)? (5 points)

public static int mystery(int n)
{
if (n > 5)
{
return
mystery(n − 2) + 2;
}

return n + 2;
}
6
8
10
12
14
2.
Consider the following method. What is the value
of mystery(1)? (5 points)

public static void mystery(int n)
{
if(n > 5)
{
System.out.print(n
+ " ");
}
else
{
mystery(n
+ 3);
}
}
1
4
7
7 4 1
1 4 7
3.
Consider the following method. What is the value
of recur("COMPUTER")? (5 points)

public static void recur(String str)
{
int len = str.length();
if(len > 1)
{
String
temp = str.substring(0, len − 2);
System.out.println(temp);

recur(temp);

}
}
C
COMPUT
COMPU
COM
C
COMPUT
COMP
CO
COMPUTE
COMPU
COM
4.
Consider the following method. What is the value
of recur("mouse", 1)? (5 points)

public static String recur(String str, int n)
{
if(n >= str.length())
{
return
str;
}

return str + recur(str.substring(n +
1), n);
}
e
use
mouse
mouseuse
mouseusee
5.
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 < 4)
{
return
2;
}
else
{
return
recur(n / 4) + 2;
}
}
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply