Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

can any one help with this question plz! NAME Recursion HW #2 Determine the outp

ID: 3816617 • Letter: C

Question

can any one help with this question plz!

NAME Recursion HW #2 Determine the output showing the box method. public static int mystery (int k, int n) if(n k) return k; else if (n k) return mystery (k, n-k): else return mystery(k-n, n) int result -mystery(6, 8) System out.println("The final answer is" result): What is the base case: What is the general case: public static int mystery2(int n) if(n 0) return -1; else if (nk 10) return n. else return ((n%10) mystery 2(n/10): int result zmystery20157): System out println("The final answer is" result): What is the base case: What is the general case:

Explanation / Answer

The base case is when n and k are same and it depends on the values.
General Case : the final answer by passing the values to method

Here n = 6, k =8
n==k false

n>k false

else
mystery (k-n,n)
mystery (2,6)

Again
n==k false
n>k false
else
mystery(4,2)

Again
n== k false
n>k true
mystery(2,2)

Again
n==k true
return 2

The final answer is 2.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at drjack9650@gmail.com
Chat Now And Get Quote