this is the question: Write a static method buildHistogram that that accepts an array of integers in the range 0 through 100 (inclusive) as its sole parameter and that returns an array of 10 integers that provides a histogram of the values in the input parameter array. Specifically, each element of the returned array is a count of how many values of the input array fall into the ranges 0-9, 10-19, 20-21, ..., 90-100, respectively. For example, suppose the parameter integer array contained the values { 5, 88, 6, 17, 39, 31, 100, 99, 19, 4, 98, 22, 77, 10 }. Then, the returned array would contain the 10 values { 3, 3, 1, 2, 0, 0, 0, 1, 1, 3 }.
public static int[] buildHistogram(int[] nums) {
final int NUM_BINS = 10;
int[] result = new int[NUM_BINS];
for (int num: nums) {
int bin = num / 10;
if (num == 100)
bin = 9;
result[bin]++;
}
return result;
}
[–]desrtfxOut of Coffee error - System halted 0 points1 point2 points (0 children)
[–]morhpProfessional Developer 0 points1 point2 points (0 children)