In this exercise I had to write a method to print stars according to the integers of an array. I have finally got my code to pass, but I did not understand exactly why. The initial value of the integer star is 1, as 0 would not work properly. Why 1 and not 0? Can any of you give me the explanation? Thank u loads!
public class Printer {
public static void main(String[] args) {
// You can test the method here
int[] array = {1,2,5,10};
printArrayInStars(array);
}
public static void printArrayInStars(int[] array) {
// Write some code in here
for (int index = 0; index < array.length; index++) {
int number = array[index];
for (int star = 1; star <= number; star++) {
System.out.print("*");
}
System.out.println("");
}
}
}