confused about this for loop/ array?
int   mat = new int  ;
for (int row = 0; row < mat.length; row ++ )
for ( int col = 0; col < mat.length; col++ )
if ( row < col )
mat [row] [col] = 1;
else if (row == col )
mat [row] [col] = 2;
mat [row] [col] = 3;
I'm completely lost as how this work, could someone break it down into simple terms for me?
Re: confused about this for loop/ array?
A 2D array requires two indexes to access an element in the array.
The posted code uses the variable row to index into the first dim of the array
and uses the variable col to index into the second dim of the array.
mat[row][col] represents one element in the array.
To see what is in the array, use the Arrays class's deepToString() method:
System.out.println("an ID "+ java.util.Arrays.deepToString(theArrayName));