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

CAI710: WQ1

Quiz
•
Computers
•
12th Grade
•
Hard
Ayesha Abdullah
Used 65+ times
FREE Resource
8 questions
Show all answers
1.
MULTIPLE CHOICE QUESTION
3 mins • 1 pt
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
Similar Resources on Quizizz
10 questions
Code.org Unit 5 Vocab Quiz 1

Quiz
•
9th - 12th Grade
12 questions
Javascript Arrays

Quiz
•
9th - 12th Grade
10 questions
Python Boolean and If

Quiz
•
9th - 12th Grade
12 questions
Python - Conditionals

Quiz
•
9th - 12th Grade
10 questions
AP CS A Unit 6 Quiz PRACTICE

Quiz
•
9th - 12th Grade
12 questions
Java Strings

Quiz
•
9th - 12th Grade
10 questions
Python Variables

Quiz
•
7th - 12th Grade
12 questions
Python - Abstractions, Comments, Data Types, Variables

Quiz
•
9th - 12th Grade
Popular Resources on Quizizz
10 questions
Chains by Laurie Halse Anderson Chapters 1-3 Quiz

Quiz
•
6th Grade
20 questions
math review

Quiz
•
4th Grade
15 questions
Character Analysis

Quiz
•
4th Grade
12 questions
Multiplying Fractions

Quiz
•
6th Grade
30 questions
Biology Regents Review #1

Quiz
•
9th Grade
20 questions
Reading Comprehension

Quiz
•
5th Grade
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
50 questions
Biology Regents Review: Structure & Function

Quiz
•
9th - 12th Grade
Discover more resources for Computers
20 questions
Types of Credit

Quiz
•
9th - 12th Grade
50 questions
Biology Regents Review: Structure & Function

Quiz
•
9th - 12th Grade
20 questions
Taxes

Quiz
•
9th - 12th Grade
20 questions
Chapter 3 - Making a Good Impression

Quiz
•
9th - 12th Grade
14 questions
Attributes of Linear Functions

Quiz
•
9th - 12th Grade
10 questions
Identifying equations

Quiz
•
KG - University
50 questions
Biology Regents Review 2: Ecology

Quiz
•
9th - 12th Grade
20 questions
Investing

Quiz
•
9th - 12th Grade