Ask Question
26 March, 18:07

Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second row contains 4 items and the final row contains 2 items?

a. int[][] items;

items = new int[3][?];

items[0] = new int[1];

items[1] = new int[4];

items[2] = new int[2]

b. int[][] items;

items = new int[3][];

items[0] = new int[1];

items[1] = new int[4];

items[2] = new int[2];

C. int[][] items;

items = new int[?][?];

items[0] = new int[1];

items[1] = new int[4];

items[2] = new int[2];

D. int[][] items;

items[0] = new int[1];

items[1] = new int[4];

items[2] = new int[2];

+4
Answers (2)
  1. 26 March, 19:07
    0
    B. int[ ][ ] items;

    items = new int[3][ ];

    items[0] = new int[1];

    items[1] = new int[4];

    items[2] = new int[2];

    Explanation:

    The first line of the snippet shows declared a multidimensional array called items. The new line, initialized items to have 3 rows. The next line items[0] then initialized the first row to contain 1 item. The next line items[1] then initialized the second row to contain 4 items. And the last line items[2] initialized the final row to contain 2 items.

    Array uses zero index counting which is why the first row is named items[0].
  2. 26 March, 21:00
    0
    b. int[][] items;

    items = new int[3][];

    items[0] = new int[1];

    items[1] = new int[4];

    items[2] = new int[2];

    Explanation:

    Code Analysis

    => Line 1.

    int [ ] [ ] items;

    This line of the code declares an int array named items and since there are two square brackets before the array name, it shows that items is a multi dimensional array.

    => Line 2.

    items = new int [3] [ ];

    This line creates a new memory location for the array items by stating the number of rows and the number of columns in it. The number in the first square bracket determines the number of rows the array items has. In this case, it has 3 rows. The second square bracket determines the number of columns each row in the array has. In this case, since nothing is specified, each row of the array can have different number of columns.

    => Line 3.

    items [0] = new int [1];

    This line takes the first row of the array (i. e items[0]) and assigns to it, a memory space that will hold one value (i. e new int[1]).

    => Line 4.

    items [1] = new int [4];

    This line takes the second row of the array (i. e items[1]) and assigns to it, a memory space that will hold four (4) values (i. e new int[4]).

    => Line 5.

    items [2] = new int [2];

    This line takes the third row of the array (i. e items [2]) and assigns to it, a memory space that will hold two (2) values (i. e new int [2]).

    Therefore, option b clearly creates the multidimensional array with the given details in the question.
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “Which of the following sets of statements creates a multidimensional array with 3 rows, where the first row contains 1 value, the second ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers