/** * Complete the following static methods for arrays * @author */ public class ArrayPractice { //Return the product of the numbers in the array public static int product(int[] array) { } //Return maximum value in the array //Return 0 if the array is empty public static int max(int[] array) { } //Return the average of the values in the array //If the array is empty, return 0 public static double average(int[] array) { } //Return the standard deviation of the values in the array //See programming project 6.6, page 376 for the formula //If the array is empty or has one element, return 0 //Hint: use the average method above to calculate the mean public static double standardDeviation(int[] array) { } //Return true if the value is found in the array //false otherwise public static boolean isFound(int[] array, int value) { } //Return a new array which contains the values of //array1 followed by the values of array2 public static int[] combine(int[] array1, int[] array2) { } //Return a String representing the array //for example: [2, 4, 9] public static String getString(int[] array) { String s = "["; for (int i = 0; i < array.length; i++) { s += array[i]; if (i != array.length - 1) s += ", "; } s += "]"; return s; } public static void main(String[] args) { int[] array = { 3, 5, 2, 8, 1, 6, 7, 9, 10}; System.out.println("Array: " + getString(array)); System.out.println("Product: " + product(array)); System.out.println("Maximum value: " + max(array)); System.out.println("Average value: " + average(array)); System.out.println("Standard deviation: " + standardDeviation(array)); System.out.println("5 in array?: " + isFound(array,5)); System.out.println("4 in array?: " + isFound(array,4)); int[] empty = {}; System.out.println("Array: " + getString(empty)); System.out.println("Product: " + product(empty)); System.out.println("Maximum value: " + max(empty)); System.out.println("Average value: " + average(empty)); System.out.println("Standard deviation: " + standardDeviation(empty)); System.out.println("5 in array?: " + isFound(empty,5)); System.out.println("4 in array?: " + isFound(empty,4)); int[] one = {5}; System.out.println("Array: " + getString(one)); System.out.println("Product: " + product(one)); System.out.println("Maximum value: " + max(one)); System.out.println("Average value: " + average(one)); System.out.println("Standard deviation: " + standardDeviation(one)); System.out.println("5 in array?: " + isFound(one,5)); System.out.println("4 in array?: " + isFound(one,4)); int[] other = {1, 5, 4}; int[] bigArray = combine(array, other); System.out.println("Big Array: " + getString(bigArray)); } }