unit 8 Flashcards
row major vs. column major
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?
3 rows, students
2 columns, tests
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
- int[][] scores = new int[][];
- int[][] scores = { {95, 89}, {75, 72}, {80, 85}};
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 = ;
int numStudents = scores.length; (# of rows)
int numTests = scores[0].length; (# of columns)
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?
m for the second for loop should be of datatype ROW, not m
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}};