Givens: n (integer) // Method fact // Given: n, an integer Results: f (integer, n factorial) public static int fact(int n) Intermediates: { Header: f fact(n) Body: } Find the sum of 1+2+…+n. Exercise 8-6 - GIVENS: n (An integer) public static int sumToN(int n) { RESULT: sumN (sum of integers from 1 to n) // Variable Declarations INTERMEDIATE: int sumN; // RESULT int m; // INTERMEDIATE m (set to n-1; smaller!) int sumM; // INTERMEDIATE sumM (sum of integers from 1 to m) HEADER: sumN sumToN(n) BODY: // Return results return(sumN); } Given an array a of n characters, reverse the values stored in positions Start to Finish. Exercise 8-7 -
Givens: n (integer) Results: f (integer, n factorial) Intermediates: Header: f fact(n) Body: // Method fact // Given: n, an integer public static int fact(int n) { } Exercise 8-6 - Find the sum of 1+2+…+n. GIVENS: n (An integer) RESULT: sumN (sum of integers from 1 to n) INTERMEDIATE: m (set to n-1; smaller!) sumM (sum of integers from 1 to m) HEADER: sumN sumToN(n) BODY: public static int sumToN(int n) { // Variable Declarations int sumN; // RESULT int m; // INTERMEDIATE int sumM; // INTERMEDIATE // Return results return(sumN); } Exercise 8-7 - Given an array a of n characters, reverse the values stored in positions Start to Finish.