1/19
Looks like no tags are added yet.
Name | Mastery | Learn | Test | Matching | Spaced |
---|
No study sessions yet.
What would be the correct way to instantiate this 2D array?
int[][] table = {
{1, 0, 10, 0},
{3, 8, 38, 0}
};
Which is the correct way to construct and assign a 2D array, with 8 rows and 10 columns, to the variable popcorn?
int[][] popcorn = new int[8][10];
We want to create a 2D double array with 6 rows and 7 columns and assign it to connectFour. Which of these is correct?
double[][] connectFour = new double[6][7];
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3, 2.3, 0.0},
{6.1, 10.2, 1.3, -2.5, -9.9},
{1.1, 2.3, 5.8, 13.21, 34.55} };
What is the value of something[1][2]?
1.3
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3, 2.3, 0.0},
{6.1, 10.2, 1.3, -2.5, -9.9},
{1.1, 2.3, 5.8, 13.21, 34.55} };
What is the value of something{2][1]?
2.3
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3, 2.3, 0.0},
{6.1, 10.2, 1.3, -2.5, -9.9},
{1.1, 2.3, 5.8, 13.21, 34.55} };
What is the value of something.length?
3
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3, 2.3, 0.0},
{6.1, 10.2, 1.3, -2.5, -9.9},
{1.1, 2.3, 5.8, 13.21, 34.55} };
What is the value of something[2].length?
5
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3, 2.3, 0.0},
{6.1, 10.2, 1.3, -2.5, -9.9},
{1.1, 2.3, 5.8, 13.21, 34.55} };
How do you replace the value 13.21 with 8.8?
something[2][3] = 8.8;
Given the following:
double[][] something =
{ {2.5, 6.8, 8.3, 2.3, 0.0},
{6.1, 10.2, 1.3, -2.5, -9.9},
{1.1, 2.3, 5.8, 13.21, 34.55} };
We want to replace the row {6.1, 10.2, 1.3, -2.5, -9.9} with a completely new array that looks like {3.1, 4.1, 5.9, 2.6, 8.4}. Which of the following lines of code will accomplish this?
double[] temp = {3.1, 4.1, 5.9, 2.6, 8.4};
something[1] = temp;
Given the following:
String[][] poem = { {"I", "am", "the", "cookie", "monster."},
{"Would", "you", "like", "a", "cookie?"},
{"COOOOKIE", "OM", "NOM", "NOM", "NOM"} };
Which of the following code fragments would produce the following output?
I am the cookie monster.
Would you like a cookie?
COOOOKIE OM NOM NOM NOM.
for (int line = 0; line < poem.length; line++)
{
for (int word = 0; word < poem[line].length; word++)
{
System.out.print(poem[line][word] + " ");
}
System.out.println();
}
Consider the following code segment, which is intended to create and initialize the 2D array words where the length of each word corresponds to the product of the indices of the row and the column it resides in.
String[][] words = /missing code /;
Which of the following initializer lists could replace /missing code/ so that the code segment works as intended?
{{"", "", ""}, {"", "b", "be"}, {"", "do", "dont"}}
Consider the following code segment, which is intended to display the word boards.
String[][] twoLetters = {{"ab", "ac", "ad","ar","af"}, {"bo", "be", "bi", "ba", "bu"},
{"ca", "ce", "ck", "co", "cs"},
{"da", "ds", "do", "de", "di"}};
System.out.println(/Missing Code/);
Which of the following can replace /Missing Code/ so the code segment works as intended?
twoLetters[1][0] + twoLetters[0][3]+ twoLetters[3][1]
Consider the following code segment:
int[][] nums = new int[5][5];
for(int i = 0; i< nums.length; i++)
{
for(int j = 0; j< nums[0].length; j++)
{
nums[i][j] = i + j;
}
}
How many instances of the number 5 will be stored in this 2D array?
4
Consider the following code segment:
String[][] word = {{"DOE", "A","DEER"},
{"A", "FEMALE", "DEER"},
{"RAY", "A", "DROP"},
{"OF","GOLDEN","SUN"}};
int counter = 0; for(String[] row: word) { for(int j = 0; j< word[0].length; j++) { if(row[j].equals(word[j+1][j])) { counter++; } } } System.out.println(counter);
What will the result of the print statement be when this code segment is executed?
4
Consider the following code segment:
int[][] arr = {{10, 9, 8},{7, 6, 5}, {4, 3, 2}};
for(int row = 0; row < arr.length; row++)
{
for(int num: arr[row])
{
System.out.println(arr[row][row] == num);
}
}
How many times will the boolean expression printed from this code segment be true?
3
Consider the following method, sumTo10, that traverses a 2D array checking to see if the sum of all integers in each array are equal to 10. The method will return true if all arrays within the 2D array sum to 10, and false otherwise.
public static boolean sumTo10(int[][] nums)
{
for(int[] row: nums)
{
int sum = 0;
int counter = 0;
while(counter < nums.length)
{
sum+=row[counter]; counter++;
}
if(sum != 10)
{
return false;
}
}
return true;
}
For example, the 2D array {{2,8}, {4, 6}} would return true because the content of each array sums to 10. The method, however, doesn't always work as intended. Which of the following 2D array input values does sumTo10 not work for?
{{9, 1, 0}, {4, 1, 5}}
Which of the following traversals would print all of the elements in the 2D array of integers nums in column-major order?
for(int row = 0; row < nums[0].length; row++)
{
for(int col = 0; col < nums.length; col++)
{
System.out.println(nums[col][row]);
}
}
Which of the following traversals would print all of the elements in the 2D array of integers nums in row-major order?
for(int col = 0; col < nums.length; col++)
{
for(int row = 0; row < nums[col].length; row++)
{
System.out.println(nums[col][row]);
}
}
Consider the following code segment:
int[][]nums = {{1, 2, 3}, {100,200,300},
{4, 6, 5},
{7,8,6}};
int sum = 0;
for(int row = 0; row < nums.length/2; row++)
{
for(int col = 0; col < nums[row].length/2; col++)
{
sum += nums[row][col];
}
}
System.out.println(sum);
What will be displayed as a result of executing this code segment?
101
Consider the following code segment:
int[][] mystery = new int[3][3];
int counter = 0;
while(counter < mystery.length)
{
for(int col = 0; col < mystery[counter].length; col++)
{
if(counter == 0)
{
mystery[col][counter] = 1;
}
else if(counter == 1)
{
mystery[counter][col] = 2;
}
else
{
mystery[counter][counter] = 3;
}
}
counter++;
}
What will the value of each element in mystery be after the execution of the code segment?
{{1, 0, 0}
{2, 2, 2}
{1, 0, 3}}