CAI710: WQ1

CAI710: WQ1

12th Grade

8 Qs

quiz-placeholder

Similar activities

APCSA Final

APCSA Final

12th Grade

10 Qs

Computer Science AP

Computer Science AP

12th Grade

10 Qs

AP Computer Science College Board Test

AP Computer Science College Board Test

12th Grade

10 Qs

AP Computer Science A Classes

AP Computer Science A Classes

12th Grade

10 Qs

Lecture 4.4 Part 1

Lecture 4.4 Part 1

12th Grade

10 Qs

Lecture 4.4 Part 2

Lecture 4.4 Part 2

12th Grade

11 Qs

Java - arrays and String methods

Java - arrays and String methods

9th - 12th Grade

12 Qs

APCS Unit 8

APCS Unit 8

12th Grade

10 Qs

CAI710: WQ1

CAI710: WQ1

Assessment

Quiz

Computers

12th Grade

Hard

Created by

Ayesha Abdullah

Used 65+ times

FREE Resource

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

8.

MULTIPLE CHOICE QUESTION

3 mins • 1 pt

Consider the following code segment.

int[][] arr = {{1, 2, 3},

{4, 5, 6},

{7, 8, 9},

{3, 2, 1}};

for (int j = 0; j < arr.length; j++){

for (int k = j; k < arr[0].length; k++){

System.out.print(arr[j][k] + " ");

}

System.out.println();

}

What output is printed when the code segment is executed?

2 3

6

1 2 3

4 5

7

1 2 3

5 6

9

1 4 7

5 8

9

1 2 3

5 6

9

1