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

To get the number of stars printed according to the value, you can modify your for loop to iterate through the array and print stars inside another nested for loop. Here's an updated version of your code:

```java
class Arrays {
public static void main(String[] args) {
int[] array1 = {5, 11, 4, 1, 7, 10, 0, 9, 12};

for (int i = 0; i < array1.length; i++) {
System.out.print(i + "\t" + array1[i] + "\t");

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

System.out.println();
}
}
}
```

In this updated code, the outer for loop iterates through each element of the array. Inside the loop, we print the element index, value, and then use another nested for loop to print the corresponding number of stars based on the value. Each iteration of the outer loop will print a new line to create the desired histogram effect.

Now, when you run this code, it will display the histogram as shown in your question.