I'm trying to create a program that prints a number of * equal to each value in an array. I'm doing this by using a method. The first iteration works and prints the number of *. But then my for loop ends and I don't know why.
package problem99_printarrayas_stars;
public class Problem99_PrintArrayAs_Stars {
public static void main(String[] args) {
int[] array = {5, 1, 3, 4, 2};
printArrayAsStars(array);
}
public static void printArrayAsStars(int[] array) {
int a =0;
for(int i = 0; i<5; i++){
while(a<array[i]){
System.out.print("*");
a++;
}
}
}
}