CSCI 2310
Fall 2009
Exercises for Quiz 8

  1. Write a Java method copy(a) that returns a copy of array a. Assume that a is an array of integers.

    Answer

  2. Write a Java method called hasNegative that takes an array of integers and returns true if the array contains any negative numbers, and false if all of the numbers in the array are nonnegative.

    Answer

  3. Write a Java method called sum that takes an array of integers and returns the sum of all of the integers in the array.

    Answer

  4. Write a Java method called reversal that takes an array s of characters as a parameter, and returns a different array that has the same characters as s, but in the reverse order. For example, if s contains characters 'a', 'b' and 'c', in that order, then reversal(s) should return an array that contains 'c', 'b' and 'a', in that order.

        public static char[] reversal(char[] s)
      

    Answer