Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Beyond Big Data Using Social MDM To Drive Deep Customer Insight

Authors: Martin Oberhofer, Eberhard Hechler

1st Edition

0133509796, 9780133509793

More Books

Students also viewed these Databases questions