Search Header Logo

CAI710: WQ1

Authored by Ayesha Abdullah

Computers

12th Grade

Used 65+ times

CAI710: WQ1
AI

AI Actions

Add similar questions

Adjust reading levels

Convert to real-world scenario

Translate activity

More...

    Content View

    Student View

8 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Media Image

What are the contents of mat after the code segment has been executed?

Media Image
Media Image
Media Image
Media Image
Media Image

2.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

A two-dimensional array arr is to be created with the following contents.


boolean[][] arr = {{false, true, false} ,

{false, false, true}};


Which of the following code segments can be used to correctly create and initialize arr ?

boolean arr[][] = new boolean[2][3];

arr[0][1] = true;

arr[1][2] = true;

boolean arr[][] = new boolean[2][3];

arr[1][2] = true;

arr[2][3] = true;

boolean arr[][] = new boolean[3][2];

arr[0][1] = true;

arr[1][2] = true;

boolean arr[][] = new boolean[3][2];

arr[1][0] = true;

arr[2][1] = true;

boolean arr[][] = new boolean[3][2];

arr[2][1] = true;

arr[3][2] = true;

3.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment, which is intended to declare and initialize the two-dimensional (2D) String array things.

/* missing code */ = {{"spices", "garlic", "onion", "pepper"},

{"clothing", "hat", "scarf", "gloves"},

{"plants", "tree", "bush", "flower"},

{"vehicles", "car", "boat", "airplane"}};

Which of the following could replace /* missing code */ so that things is properly declared?

new String[][] things

new(String[][]) things

String[] String[] things

String[][] things

[][]String things

4.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment.

int[][] array2D = {{1, 2, 3, 4},

{5, 6, 7, 8},

{9, 10, 11, 12},

{13, 14, 15, 16}};


for (int[] i : array2D){

for (int x : i){

System.out.print(x + " ");

}

System.out.println(" ");

}

How many times will the statement System.out.print(x + " ") be executed?

3 times

4 times

6 times

12 times

16 times

5.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

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 ?

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

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

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

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

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

6.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

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?

letters[1][0] + letters[2][2] + letters[2][0]

letters[2][1] + letters[3][3] + letters[3][1]

letters[2][0] + letters[2][2] + letters[1][0]

letters[1][2] + letters[3][3] + letters[1][3]

letters[0][1] + letters[2][2] + letters[0][2]

7.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

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?

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

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

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

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

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

Access all questions and much more by creating a free account

Create resources

Host any resource

Get auto-graded reports

Google

Continue with Google

Email

Continue with Email

Classlink

Continue with Classlink

Clever

Continue with Clever

or continue with

Microsoft

Microsoft

Apple

Apple

Others

Others

Already have an account?