// Helene Martin, CSE 142 // Demonstrates passing arrays as parameters and returning them from methods. import java.util.*; public class ArrayExamples { public static void main(String[] args) { int[] test = {4, 2, 6, 2}; System.out.println(sum(test)); int[] test2 = {5, 5, 7, 7}; System.out.println(Arrays.toString(merge(test, test2))); } // returns the sum of the elements in an array public static int sum(int[] a) { int sum = 0; for (int i = 0 ; i < a.length; i++) { sum += a[i]; } return sum; } // returns a new array containing values in a followed // by values in b public static int[] merge(int[] a, int[] b) { int[] result = new int[a.length + b.length]; for (int i = 0; i < a.length; i++) { result[i] = a[i]; } for (int i = 0; i < b.length; i++) { result[i + a.length] = b[i]; } return result; } }