In the nested for loop for a basic 2D String array I came across this:
array = new String [5][10];
for(int i=0; i<array.length;i++)
{
for(int j=0; j<array[0].length;j++)
{
System.out.print(array[i][j]="*");
}
System.out.println("");
}
Now this is what I want to know, why does the second for statement include array[0].length rather than array.length like in the for statement before it?
All I could extract from this while experimenting was if both for statements contained array.length and the 2D array was a 5x10, it would print it as a 5x5, but with array[0].length it would print a correct 5x10.
So why does this little adjustment fix everything?