This preview has intentionally blurred sections. Sign up to view the full version.
View Full DocumentThis preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CSE 114 Practice Midterm Exam 2 Thursday, October 21, 2004 NAME (please print legibly): Your University ID Number: NO BS bonus: If you do not know the answer to a problem and leave it blank you will receive 1 point for each subpart (e.g., a,b,c, etc.) that you leave blank. If you write anything in the space and it is wrong, you will receive a zero. Thus, the score for a completely blank exam is 12. You will not lose any points for small coding details such as misspelling a method name, leaving out some default method arguments, or getting the order of method arguments wrong. QUESTION VALUE SCORE 1 10 2 25 3 15 4 10 5 20 6 15 TOTAL 95 1 1. (10 points) Write a recursive method sum() that computes the sum of the numbers from 1 to n using the following recursive definition: the sum of 1 to n is equal to the sum of 1 to ( n /2) plus the sum of ( n /2 + 1) to n. public int sum (int a, int n) { if (a == n) return a; else { n2 = n / 2; if (n2 < a) n2 = a; return sum(a, n2) + sum(n2+1, n); } } 2 2. (25 points)2....
View
Full Document
 Spring '08
 TASHBOOK
 Subroutine, advisor, public int sum, private int classYear

Click to edit the document details