Professional Documents
Culture Documents
AP COMPUTER SCIENCE A
1. Write a method named totalSum that receives an integer array as a parameter and returns the sum of
all of its elements. See the examples below for the expected output of totalSum.
2. Write a method named countTotal that receives a double array as a parameter and returns the
total number of elements in the array. See the examples below for the expected output of
countTotal. You should be able to do this problem without a loop.
page 1
AP COMPUTER SCIENCE A
3. Write a method named buildArray that receives an integer, n, as a parameter and returns an integer
array of length n. The value of each element in the array should be equal to its index. See the
examples below for the expected output of buildArray.
4. Write a method named negateArray that receives an integer array, nums. negateArray should
return an integer array in which every element of nums has been flipped to its opposite (i.e., negated).
See the examples below for the expected output of negateArray.
int[] stuff = {3, 4, 5}; negateArray (stuff) → {-3, -4, -5}
int[] nums = {0, -1, -2, -3}; negateArray (nums) → {0, 1, 2, 3}
page 2
AP COMPUTER SCIENCE A
5. Write a method named getAverage that receives an integer array as a parameter and returns the
average of the elements in the array. See the examples below for the expected output of getAverage.
You may assume the array will contain at least one element.
page 3