Question: 1. Assume that a two-dimensional (2D) array arr of String objects with 3 rows and 4 columns has been properly declared and initialized. Which of

1. Assume that a two-dimensional (2D) array arr of String objects with 3 rows and 4 columns has been properly declared and initialized.

Which of the following can be used to print the elements in the four corner elements of arr ?

  • A. System.out.print(arr[0, 0] + arr[0, 3] + arr[2, 0] + arr[2, 3]);

  • B. System.out.print(arr[1, 1] + arr[1, 4] + arr[3, 1] + arr[3, 4]);

  • C. System.out.print(arr[0][0] + arr[0][2] + arr[3][0] + arr[3][2]);

  • D. System.out.print(arr[0][0] + arr[0][3] + arr[2][0] + arr[2][3]);

2. Consider the following code segment, where letters is a two-dimensional (2D) array that contains possible letters. The code segment is intended to print "DIG".

String[][] letters = {{"A", "B", "C"},

{"D", "E", "F"},

{"G", "H", "I"}};

System.out.println( /* missing code */ );

Which of the following could replace /* missing code */ so that the code segment works as intended?

  • A. letters[2][1] + letters[3][3] + letters[3][1]

  • B. letters[2][0] + letters[2][2] + letters[1][0]

  • C. letters[1][2] + letters[3][3] + letters[1][3]

  • D. letters[1][0] + letters[2][2] + letters[2][0]

  • E. letters[0][1] + letters[2][2] + letters[0][2]

3. Consider the following code segment, where nums is a two-dimensional (2D) array of integers. The code segment is intended to print "test1234".

System.out.print("test" + nums[0][0] + nums[1][0] + nums[1][1] + nums[0][1]);

Which of the following code segments properly declares and initializes nums so that the code segment works as intended?

  • A. int[][] nums = {{1, 2}, {3, 4}};

  • B. int[][] nums = {{1, 2}, {4, 3}};

  • C. int[][] nums = {{1, 3}, {2, 4}};

  • D. int[][] nums = {{1, 4}, {2, 3}};

  • E. int[][] nums = {{1, 4}, {3, 2}};

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!