import java.util.Arrays; public class Question01 { public static void main(String[] args) { //a) Create a int array of size 50. int[] arr = new int[50]; //b) Using a for loop, assign a random value between 1 and 10 to each element. for (int i = 0; i < arr.length; i++) { arr[i] = (int)(Math.random() * 10 + 1); } //c) Implement the function outputArray and test it. (See below of function.) outputArray(arr); //d) Make use of Arrays.toString() to output the content of the array using a single line of code. System.out.println(Arrays.toString(arr)); //e) Implement and test the occurenceCounter function. System.out.println("Amount of 7s in array: " + occurenceCounter(arr, 7)); System.out.println("Amount of 3s in array: " + occurenceCounter(arr, 3)); //f) Implement and test the maxIndex function. System.out.println("The max value is at index " + maxIndex(arr)); } //c) Implement the outputArray function. public static void outputArray(int[] a) { for (int i = 0; i < a.length; i++) { System.out.print(a[i] + ", "); } System.out.println(""); //end of line } //e) Implement the occurenceCounter function. public static int occurenceCounter(int[] a, int value) { int count = 0; for (int i = 0; i < a.length; i++) { if (a[i] == value) { count++; } } return count; } //f) Implement the maxIndex function. public static int maxIndex(int[] a) { int mIndex = 0; for (int i = 0; i < a.length; i++) { if (a[i] > a[mIndex]) { mIndex = i; } } return mIndex; } }