Answer:
public class BarChartPrinting {
public static void main (String [] args) {
int numbers[] = new int[5];
Scanner input = new Scanner(System.in);
for (int i = 0; i < 5; i++){
System.out.print("Enter a number between 1 to 30: ");
numbers[i] = input.nextInt();
}
for (int i = 0; i < 5; i++){
for (int j = 0; j < numbers[i]; j++){
System.out.print("*");
}
System.out.println("");
}
}
}
Explanation:
- Initialize the <em>numbers</em> array to hold the numbers
- Inside the <u>for loop</u>, get the numbers from the user and put them in the <em>numbers</em>
- Inside the <em>nested for loop</em>, print the asterisks, depending on the number that is in the <em>numbers</em> array
The outer loop will iterate five times corresponding to the each number in the array, and inner loop will print the asterisks depending on the value of the number