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( “

” );
document.writeln(“

” );
document.writeln( “” );
for ( var i in t ) {
document.writeln( “” );
for ( var j in t[ i ] )
document.write( “” );
document.writeln( “” );
}
document.writeln( “
 012
” + i + “” + t[ 1 ][ j ] + “
” );
```

Computer Science & Information Technology

You might also like to view...

Define the term” simple sequence code.”

What will be an ideal response?

Computer Science & Information Technology

Create a class called Complex for performing arithmetic with complex numbers. Write a driver program to test your class. Complex numbers have the form realPart + imaginaryPart * i where i is ?-1

Use floating-point numbers to represent the data of the class. Provide a constructor that enables an object of this class to be initialized when it is created. The constructor should contain default values in case no initializers are provided. Provide methods for each of the following: a) Adding two ComplexNumbers: The real parts are added together to form the real part of the result, and the imaginary parts are added together to form the imaginary part of the result. b) Subtracting two ComplexNumbers: The real part of the right operand is subtracted from the real part of the left operand to form the real part of the result, and the imaginary part of the right operand is subtracted from the imaginary part of the left operand to form the imaginary part of the result. c) Printing ComplexNumbers in the form (a, b), where a is the real part and b is the imaginary part.

Computer Science & Information Technology

One person is selected at random from a class of 13 males and 11 females. Find the odds against selecting a female.

A. The odds against selecting a female are 13 : 11. B. The odds against selecting a female are 13 : 24. C. The odds against selecting a female are 11 : 24. D. The odds against selecting a female are 1 : 1. E. The odds against selecting a female are 11 : 13.

Computer Science & Information Technology

The Pattern layer style varies the color and opacity of a gradient.

Answer the following statement true (T) or false (F)

Computer Science & Information Technology