unit 8 Flashcards

1
Q

row major vs. column major

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

consider a 2d int array, scores, that holds the score for 2 tests, across 3 students, as follows:

95 89
75 72
80 85

how many rows?
how many columns?
what do they represent?

A

3 rows, students
2 columns, tests

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

consider a 2d int array, scores, that holds the score for 2 tests, across 3 students, as follows:

95 89
75 72
80 85

write a statement to DECLARE, NOT INITIALIZE scores, then write a SEPARATE statement to declare AND initialize scores given the data above

A
  1. int[][] scores = new int[][];
  2. int[][] scores = { {95, 89}, {75, 72}, {80, 85}};
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

consider a 2d int array, scores, that holds the score for 2 tests, across 3 students, as follows:

95 89
75 72
80 85

complete the following statements w/ the appropriate statistic:
int numStudents = ;
int numTests = ;

A

int numStudents = scores.length; (# of rows)
int numTests = scores[0].length; (# of columns)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

in the following code:

private static double positiveMax(double[][] m)
{
    double max = 0;
    for (double[] row : m)
        for (double column : m)
            if (column > max) 
                max = column;
    return max;
}

what is the error?

A

m for the second for loop should be of datatype ROW, not m

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

A two-dimensional array myArray is to be created with the following contents.

{{0, 0, 3},

{0, 0, 0},

{7, 0, 0}}

Which of the following code segments can be used to correctly create and initialize myArray ?

A.
int[][] myArray = new int[3][3];
myArray[0][2] = 3;
myArray[2][0] = 7;

B.
int[][] myArray = new int[3][3];
myArray[0][2] = 7;
myArray[2][0] = 3;

C.
int[][] myArray = {{0, 0, 3}, {0, 0, 0}, {7, 0, 0}};

A
How well did you know this?
1
Not at all
2
3
4
5
Perfectly