6) Assume the student has access to the following method: int example (int n) {
ID: 3652340 • Letter: 6
Question
6) Assume the student has access to the following method: int example (int n) { if (n == 0) return 0; else return example (nExplanation / Answer
6) Assume the student has access to the following method: int example (int n) { if (n == 0) return 0; else return example (n – 1) + n*n*n; } 8. What does the example method do, when passed a positive int n? b) Returns the sum of the cubes of the numbers 0 to n. 7) Assume the student has access to the following method: int example (int n) { if (n == 0) return 0; else return example (n – 1) + n*n*n; } How many base cases are there in example? b) 1 8) Assume the student has access to the following method: int example (int n) { if (n == 0) return 0; else return example (n – 1) + n*n*n; } What is returned from the call example(3)? 36 9) Questions 17 to 21 assume the student has access to the following method: int tq (int num) { if (num == 0) return 0; else if (num > 100) return -1; else return num + tq ( num – 1 ); } Is there a constraint on the value that can be passed as an argument in order for tq to pass the smaller-caller test? If so, what is it? if num=1 or num>=102, you'll exit your fxn pretty quickly b/c of hitting the base case num=0 or num>100 10) Questions 17 to 21 assume the student has access to the following method: int tq (int num) { if (num == 0) return 0; else if (num > 100) return -1; else return num + tq ( num – 1 ); } Is tq(4) a valid call? If so, what is returned from the method? 10
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.