Question : Write a Java program to read integer data set(size of n<10) into an array and display its data graphically by plotting each numeric value as a bar of asterisks as shown in the following table.

Element Value Histogram
0 5 *****
1 11 ***********
2 4 ****
3 1 *
4 7 *******
5 10 **********
6 0
7 9 *********
8 12 ************

My work :

My first thought was to do this using a for loop : accessing one element of the array at a time and then printing stars according to the value;

Below is the code, but I don't know how to get the no. of stars printed according the value . Any help on this is highly appreciated. Thanks!

class arrays{

public static void main(String[] args) {

int[] array1 = {5, 11, 4, 1, 7, 10, 0, 9, 12};

int i = 0;

for (int x = array1[i]; i <= 8; i++) {
System.out.print("*");
System.out.println();
}


}
}
10