Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Given int[][] table = new int[2][10], Which of the following code fill all value

ID: 3877696 • Letter: G

Question

Given int[][] table = new int[2][10], Which of the following code fill all values in a two dimensional array with 0?

Question 21 options:

for (int row=0; row < =table.length; row++)

         for (int col=0; col <= table[row].length; col++)

           table[row][col] = 0;

for (int row=0; row < 2; row++)

         for (int col=0; col < 10; col++)

           table[row][col] = 0;

for (int row=0; row < table.length; row++)

         for (int col=0; col < table[col].length; col++)

           table[row][col] = 0;

for (int row=0; row < table.length-1; row++)

         for (int col=0; col < table[row].length; col++)

           table[row][col] = 0;

A)

for (int row=0; row < =table.length; row++)

         for (int col=0; col <= table[row].length; col++)

           table[row][col] = 0;

B)

for (int row=0; row < 2; row++)

         for (int col=0; col < 10; col++)

           table[row][col] = 0;

C)

for (int row=0; row < table.length; row++)

         for (int col=0; col < table[col].length; col++)

           table[row][col] = 0;

D)

for (int row=0; row < table.length-1; row++)

         for (int col=0; col < table[row].length; col++)

           table[row][col] = 0;

Explanation / Answer

Correct Option:

B . for (int row=0; row < 2; row++)

         for (int col=0; col < 10; col++)

           table[row][col] = 0;

A) is incorrect as table[row].length is incorrect way to compute columns in the table . length is used to find the length of one dimensional array.

C) is incorrect for same reason as table[col].length is incorrect way to compute size of columns.

D) is also incorrect as table[row].length is wrong way to compute size of columns in a row.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote