Via the starPrint method I need to make the frequency of each number populated in the array display in a histogram as such:
1=3***
2=4****
3=7*******
and so on. It needs the number of stars populated that are equal to the frequency of the number appearing! At the moment I'm getting the number of asterisks of the length of the array.
public static void main(String[] args) {
int matrix[][] = new int[100][2];
for (int row = 0; row < matrix.length; row++) {
for (int column = 0; column < matrix[row].length; column++) {
matrix[row][column] = (int) (Math.random() * 6 + 1);
}
}
int[] hist1 = frequency(matrix);
String star = starPrint(hist1);
for (int i = 1; i < hist1.length; i++) {
System.out.print(" \n" + hist1[i] + star);
}
}
public static String starPrint(int[] value) {
String star = "";
for (int i = 0; i < value.length; i++) {
star += "*";
}
return star;
}
public static int[] frequency(int[][] matrix) {
int[] nums = new int[7];
for (int i = 0; i < matrix.length; i++) {
for (int j = 0; j < matrix[i].length; j++) {
nums[matrix[i][j]] += 1;
}
}
return nums;
}