Services
Discover
Ask a Question
Log in
Sign up
Filters
Done
Question type:
Essay
Multiple Choice
Short Answer
True False
Matching
Topic
Computing
Study Set
Big Java Binder Early Objects
Exam 13: Recursion
Path 4
Access For Free
Share
All types
Filters
Study Flashcards
Practice Exam
Learn
Question 101
Multiple Choice
Recursion will take place if any of the following happen: I method A calls method B, which calls method C II method A calls method B, which calls method A III method A calls method A
Question 102
Multiple Choice
Consider the fib method from the textbook shown below: public static long fib(int n) { If (n <= 2) { Return 1; // line #1 } Else { Return fib(n - 1) + fib(n - 2) ; // line #2 } } Assume line #2 is changed to this: Else { return 2 * fib(n - 1) + 2 * fib(n - 2) ; } What effect will this change have?
Question 103
Multiple Choice
Consider the recursive square method shown below. It takes a non-negative int argument. Then it recursively adds the number n to itself n times to produce the square of n. Complete the correct code for the square helper method. public int square(int n) { ____________________; } Public int square(int c, int n) { If (c == 1) { Return n; } Else { Return n + square(c - 1, n) ; } }
Question 104
Multiple Choice
Consider the helper method reversePrint, which uses recursion to display in reverse the elements in a section of an array limited by the firstIndex and lastIndex arguments. What statement should be used to complete the recursive method? public static void reversePrint(int[] array, int firstIndex, int lastIndex) { If (firstIndex < lastIndex) { ________________________________________ } System.out.println(array[firstIndex]) ; } Public static void main(String[] args) { Int [] numbers = { 4, 7, 1, 0, 2, 7 }; ReversePrint(numbers, 0, numbers.length - 1) ; }
Question 105
Multiple Choice
Consider the mutually recursive methods below. Select the method call that could be used to generate the output sequence: A5 B4 A3 B2 A1 public static void methodA(int value) { If (value > 0) { System.out.print(" A" + value) ; MethodB(value - 1) ; } } Public static void methodB(int value) { If (value > 0) { System.out.print(" B" + value) ; MethodA(value - 1) ; } }
Question 106
Multiple Choice
Consider the recursive method myPrint in this code snippet: public void myPrint(int n) { If (n < 10) { System.out.print(n) ; } Else { Int m = n % 10; System.out.print(m) ; MyPrint(n / 10) ; } } What is printed for the call myPrint(821) ?