total 0 fork 0 k tempslength k total tempsk avgTemp total k We informally

# Total 0 fork 0 k tempslength k total tempsk avgtemp

• Notes
• 5
• 93% (60) 56 out of 60 people found this document helpful

This preview shows page 2 - 4 out of 5 pages.

total = 0; for(k = 0; k < temps.length; k++) { total += temps[k]; } avgTemp = total / k; We informally define the term corresponding element as follows: The first element in an array and the last element of the array are corresponding elements. Similarly, the second element and the element just before the last element are corresponding elements. The third element and the element just before the element just before the last element are corresponding elements -- and so on. Given an array a, write an expression for the corresponding element of a[i]. a[a.length - 1 - i] Reversing the elements of an array involves swapping the corresponding elements of the array: the first with the last, the second with the next to the last, and so on, all the way to the middle of the array. Given an array a and two other int variables, k and temp, write a loop that reverses the elements of the array. Do not use any other variables besides a, k, and temp. for(k = 0; k < a.length/2; k++) { temp = a[k]; a[k] = a[a.length - k - 1]; a[a.length - k - 1] = temp; } Given:an int variable k, an int array currentMembers that has been declared and initialized, an int variable memberID that has been initialized, and an boolean variable isAMember, write code that assigns true to isAMember if the value of memberID can be found in currentMembers, and that assigns false to isAMember otherwise. Use only k, currentMembers, memberID, and isAMember. isAMember = false; for(k = 0; k < currentMembers.length; k++) { if (currentMembers[k] == memberID) isAMember = true; } You are given an int variable k, an int array zipcodeList that has been declared and initialized, and a boolean variable duplicates.  • • • 