You are using for(int i=0; i<array.length; i++)
to iterate over the values of the array. So you actually wants to use array[i]
and not something else. In your case you want to iterate over the names which you have defined. The count array however is filled with zeros and the question is why you want to iterate over them. So if you write
String breads[] = {"Brown", "White", "Sandwich"};
int count[] = new int[breads.length];
for (int i = 0; i < breads.length; i++) {
}
you clearly see that the loop is for iterating over the names. And you deal with these names (like showing them). But if you write
String breads[] = {"Brown", "White", "Sandwich"};
int count[] = new int[breads.length];
for (int i = 0; i < count.length; i++) {
}
The question rise why do you want to iterate over the count values? they are all 0.
The data flow actually is something like count_value = f(bread_value)
, the bread names are the independent variable. You can write (in Java)
String breads[] = {"Brown", "White", "Sandwich"};
int count[] = new int[breads.length];
for (String bread: breads) {
}
and clearly sees that you care about the bread names and wants to do something with them. That you want to set the counts are just a side affect of the loop, but it doesn't control the times of iterations.