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("");
}
}
}
Step-by-step explanation:
- Initialize the numbers array to hold the numbers
- Inside the for loop, get the numbers from the user and put them in the numbers
- Inside the nested for loop, print the asterisks, depending on the number that is in the numbers 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