S A M P L E CPS 1 (Ramm) Spring 1998 18 February 1998 Quiz #5 Name ___________________ Honor Code________________________ Section _____ A. Assume you have Java code which includes an array of doubles named t. Also assume that we have gotten data into this array as suggested by the diagram below. Also assume there were all of the needed declarations, etc., which are omitted here. 0 1 2 3 4 5 6 7 8 9 ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ t | 30.0 | 70.0 | 15.0 | 85.0 | 30.0 | 70.0 | 80.0 | 20.0 | 25.0 | 75.0 | ------ ------ ------ ------ ------ ------ ------ ------ ------ ------ After the following code runs, what will be shown in the TextField symbolized by the rectangle below? ... n = 10; extreme = t[0]; total = 0.0; k = 0; while (k < n) { if (t[k] > extreme) { extreme = t[k]; } total = total + t[k]; k = k + 1; } mResult.setText("extreme = "+extreme+" sum = "+total+" count = "+k); ... --------------------------------------------------------------------- | | --------------------------------------------------------------------- B. The following code fragment "processes" an array of 500 integers called data. Complete it to count the number of negative values stored in the array. The lines suggest places to put code. (There may be too many lines.) Declarations are omitted. ____________________ n = 500; k = 0; while (k < n) { if (___________________) { ____________________ ____________________ } k = k + 1; } mAnswer.setText("The number of negative numbers is " + ___________);