Ask Question
Yesterday, 21:18

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];

+2
Answers (1)
  1. Yesterday, 21:40
    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?
Find 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 the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers