194k views
4 votes
Consider the following code segment, which is intended to create and initialize the two-dimensional (2D) integer array num so that columns with an even index will contain only even integers and columns with an odd index will contain only odd integers.

int[][] num = /* missing code */;
Which of the following initializer lists could replace /* missing code */ so that the code segment will work as intended?
A. {{0, 1, 2}, {4, 5, 6}, {8, 3, 6}}
B. {{1, 2, 3}, {3, 4, 5}, {5, 6, 7}}
C. {{1, 3, 5}, {2, 4, 6}, {3, 5, 7}}
D. {{2, 1, 4}, {5, 2, 3}, {2, 7, 6}}
E. {{2, 4, 6}, {1, 3, 5}, {6, 4, 2}}

User Iqfareez
by
4.0k points

2 Answers

6 votes

Answer:

A

Step-by-step explanation:

because the index is even

User Varikin
by
4.2k points
4 votes

Answer:

A. {{0, 1, 2}, {4, 5, 6}, {8, 3, 6}}

Step-by-step explanation:

From the options, we can see that the array is a 3 by 3 array and the array index (whether row or column) begins at 0.

So, the column index for this array is 0, 1 and 2.

Column number 0 and 2 will be treated as the even column while column number 1 will be treated as the odd columns.

Of all options (a) to (e), option (a) fits the requirement of the question; hence; (a) answers the question.

User Neoryder
by
4.6k points