GIVENS: a (An array of numbers) // Method upToNSame Are elements up to n in a – n (Number of array elements to test) public static boolean upToNSame(int[] a, int n) RESULT: isEqual (Boolean: TRUE if all values in { elements up to position n are equal) // VARIABLE DECLARATION / DATA DICTIONNARY INTERMEDIATE: boolean partialRes; // INTERMEDIATE: partial result boolean isEqual; partialRes (partial result) // RESULT: expected result // ALGORITHM BODY HEADER: isEqual upToNSame(a, n) BODY: // RETURN RESULT return isEqual; } Efficient Version // Method upToNSame efficient version – public static boolean upToNSame(int[] a, int n) { // VARIABLE DECLARATION / DATA DICTIONNARY boolean isEqual; // RESULT: expected result // ALGORITHM BODY // RETURN RESULT return isEqual; } Exercise 8-5 Calculate n !. -
GIVENS: a (An array of numbers) n (Number of array elements to test) RESULT: isEqual (Boolean: TRUE if all values in elements up to position n are equal) INTERMEDIATE: partialRes (partial result) HEADER: isEqual upToNSame(a, n) BODY: Efficient Version // Method upToNSame – Are elements up to n in a public static boolean upToNSame(int[] a, int n) { // VARIABLE DECLARATION / DATA DICTIONNARY boolean partialRes; // INTERMEDIATE: partial result boolean isEqual; // RESULT: expected result // ALGORITHM BODY // RETURN RESULT return isEqual; } // Method upToNSame – efficient version public static boolean upToNSame(int[] a, int n) { // VARIABLE DECLARATION / DATA DICTIONNARY boolean isEqual; // RESULT: expected result // ALGORITHM BODY // RETURN RESULT return isEqual; } Exercise 8-5 - Calculate n !.
ITI1120WorkBook.docx