Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

public static int[] histogram (int[] ages) This method should count up how many

ID: 3528492 • Letter: P

Question

public static int[] histogram (int[] ages) This method should count up how many times each integer occurs within the input array, and return a new array with these counts. The new array size should be one more than the maximum value in the input array. (It will be a different size than the input array!) Each element in this new array should contain a count, element i should contain the number of times that i appears in the input array. The input array should not be changed. Example: If the input array contains: 4 0 2 3 3 2 1 3 4 6 2 5 3 3 2 then the output array would contain: 1 1 4 5 2 1 1 (There is 1 zero, 1 one, 4 twos, 5 threes, 2 fours, one five, and one six in the input array.) public static File[] getUnique(File[] files) This method should create and return a new array of File objects. The array should contain the unique File objects found in the input array (a set of File objects). The input array should not be changed. Note that you do not need to create new File objects, just a new array of references to existing File objects. public static Rectangle findSmallest(Rectangle[] rectangles) This method should find and return a reference to the smallest rectangle from the array of rectangles. The smallest rectangle is the rectangle with the smallest area. The input array should not be changed. Notes: Each method has a specific set of requirements listed in the JavaDoc comments for the method. Make sure you follow them exactly. (Your method should behave exactly as described, with no additional functionality.) Common sense is required - the assignment is not meant to be overly complex. You should keep your solutions simple, and don't do any extra work that you don't need to. (In particular, you don't need to worry about throwing exceptions, testing input data for validity, or printing out messages in the class.) This assignment is designed to allow you to practice your problem solving skills. Each of these programming problems can be broken down into subproblems. For example, the histogram method requires you to find the maximum value in an array, create a new array object, and count values in an array using another array to store the counts.

Explanation / Answer

int [] array = new int [] {1,3,3}; int [] anotherArray = new int [10]; int counter = 0; for(int i = 0; i < 4; i++) { for(int k = 0; k < array.length; k++) { if(array[k]== i) counter+= 1; } anotherArray[i] = counter; System.out.println(anotherArray[i]); }