Consider a 2-by-3 array t that will store integers.
a) Write a statement that declares and creates array t.
b) How many rows does t have?v
c) How many columns does t have?
d) How many elements does t have?
e) Write the names of all the elements in the second row of t.
f) Write the names of all the elements in the third column of t.
g) Write a single statement that sets the element of t in row 1 and column 2 to zero.
h) Write a series of statements that initializes each element of t to zero. Do not use a repetition structure.
i) Write a nested for structure that initializes each element of t to zero.
j) Write a series of statements that determines and prints the smallest value in array t.
k) Write a statement that displays the elements of the first row of t.
l) Write a statement that totals the elements of the fourth column of t.
a)
```
var t = new Array( 2 );
t[ 0 ] = new Array( 3 );
t[ 1 ] = new Array( 3 );
```
b) 2.
c) 3.
d) 6.
e) t[ 1 ][ 0 ], t[ 1 ][ 1 ], t[ 1 ][ 2 ].
f) t[ 0 ][ 2 ], t[ 1 ][ 2 ].
g) t[ 1 ][ 2 ] = 0;
h)
```
t[ 0 ][ 0 ] = 0;
t[ 0 ][ 1 ] = 0;
t[ 0 ][ 2 ] = 0;
t[ 1 ][ 0 ] = 0;
t[ 1 ][ 1 ] = 0;
t[ 1 ][ 2 ] = 0;
```
i)
```
for ( var j = 0; j < t.length; j++ )
for ( var k = 0; k < t[ j ].length; k++ )
t[ j ][ k ] = 0;
or
for ( var j in t )
for ( var k in t[ j ] )
t[ j ][ k ] = 0;
```
j)
```
// assume small is declared and initialized.
for ( var x = 0; x < t.length; x++ )
for ( var y = 0; y < t[ x ].length; y++ )
if ( t[ x ][ y ] < small )
small = t[ x ][ y ];
document.writeln( “Smallest is ” + small );
```
k)
```
document.writeln( t[ 0 ][ 0 ] + “ ” + t[ 0 ][ 1 ] + “ ” + t[ 0 ][ 2 ] );
```
l) t does not have a fourth column.
m)
```
document.writeln( “
  | 0 | 1 | 2 |
---|---|---|---|
” + i + “ | ” );” + t[ 1 ][ j ] + “ | ” );
```