I just don't understand how this code is working. I went through it with a pen and paper and it seems to only initialise the first column, but when I run it it works as expected. I'm clearly missing something. Could someone explain this like I'm five? (I understand the difference between array.length and array[0].length)
public static void main(String[] args) {
final int rows=10,columns=5;
int[][] twoDArray = new int [rows][columns];
twoDArray[0][0]=0;
twoDArray[0][1]=1;
for (int i =0;i<twoDArray.length;++i){
for (int j =0;j<twoDArray[0].length;++j){
twoDArray[i][j]=i*twoDArray[0].length+j;
}
}
for (int i =0;i<twoDArray.length;++i)
{ for (int j=0;j<twoDArray[0].length;++j)
{
System.out.println("The element at twoDArray["+i+"]"+"["+j+"] is: " + twoDArray[i][j]);
}
}
}
}