Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

1)

2

2)

3

3)

4

4)

5

5)

9

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:

1)

2

2)

8

3)

10

4)

2 4 6 8 10

5)

10 8 6 4 2

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:

1)

PU

2)

OMPUTE

3)

PU MPUT OMPUTE

4)

OMPUTE MPUT PU

5)

COMPUT OMPU MP

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:

1)

se

2)

use

3)

mouse

4)

mousese

5)

mouseousee

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Concepts

Authors: David M. Kroenke

1st Edition

0130086509, 978-0130086501

More Books

Students also viewed these Databases questions

Question

=+ How well do you think you could do your job?

Answered: 1 week ago