Answered step by step
Verified Expert Solution
Question
1 Approved Answer
37. Fill in the code below in the underline: public class Test ( public static void main(Stringl) args) ( Test test new Test); test.setAction public
37. Fill in the code below in the underline: public class Test ( public static void main(Stringl) args) ( Test test new Test); test.setAction public void setAction(T1 t) t.m): interface T1 public void m; a. 0-> System.out.print"Action 1!") b. (e)->System.out.print("Action 1! ") c.System.out.print("Action 1!") d. (e)->(System.out.printf" Action 1!") 38. Fill in the code to complete the following method for computing factorial. /* Return the factorial for a specified index* public static long factorial(int n) f if (n 0) // Base case return 1; else returnI /Recursive call a. n (n-1) b. n factorial(n -1) c. factorial(n -1) d. Both b & c se Analyse the following recursive method. gublic static long factorial(int n) return n *factorial(n 1) a Invoking factorial(O) returns 0, b invoking factorial(1) returns 1. c. Invoking factorial(2) returns 2. d. Invoking factorial(3) returns 6 e The method runs infinitely and causes a StackOverflowError. 40 What is the return value for xMethod(4) after calling the following method? static int xMethod(int n)f f (n 1) return 1; else return n + xMethod(n -1) a. 12 C 10 d. 9 41. Fill in the code to complete the following method for computing a Fibonacci number. public static long fib(long index) if (index 0)// Base case return 0; else if (index-1)// Base case return 1 else I/ Reduction and recursive calls return a. fib(index-1) b. fiblindex-2) c.fiblindex-1)+ fib(index-2) d. None of the above
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access with AI-Powered 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