1. What would print as a result of the code block below? (3 points) String[][] friends = { {"Jamal", "Suzy"}, {"Xander"

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899604
Joined: Mon Aug 02, 2021 8:13 am

1. What would print as a result of the code block below? (3 points) String[][] friends = { {"Jamal", "Suzy"}, {"Xander"

Post by answerhappygod »

1.
What would print as a result of the code block below? (3
points)

String[][] friends = { {"Jamal", "Suzy"}, {"Xander", "Sloan"},
{"Thomas", "Aaron"} };
String name = friends[2][1];
System.out.println(name + " is at location, [2,1]");
Aaron is at location, [2,1]
Thomas is at location, [2,1]
Sloan is at location, [2,1]
Xander is at location, [2,1]
An ArrayIndexOutOfBoundsException occurs
2.
double[][] gpas = {{4.2, 3.0, 7.2, 1.8},{2.2, 3.5, 3.0,
6.4},{4.3, 3.9, 3.2, 2.9}} ;

What is the value of gpas[2].length? (3 points)
0
1
2
3
4
3.
Give the following code, what would complete the missing code
block to only print the elements of the array that are even numbers
? (3 points)

int[][] array = { {1,2,3,4},{5,6,7,8},{9,10,11,12}};
for (int out = 0; out < array.length; out++)
{
for
(int in = 0; in < array[0].length; in++)
{
**
missing code **
}
}
I only
II only
III only
I and II
I and III
4.
Consider the 2d array below.

String[][] names = {{"Abby", "Bobby", "Charles", "David"}, {"Eric",
"Faith", "Gina", "Hope"}, {"Ines", "Juan", "Karl", "Lily"}};

What would be printed out by the following code: (3 points)

for(int b = 1; b < names[0].length-1; b++){
for(int a = 1; a < names.length;
a++){

System.out.print(names[a] + " ");
}
}
Bobby Faith Juan Charles Gina Karl
Faith Juan Gina Karl
Bobby Charles Faith Gina
Faith Juan Charles Gina
Nothing prints, an error occurs
5.
What is the value of val after the code below is
executed? (3 points)

int[][] numbers = { {3,1,5,2},{1,8,2,4},{1,2,4,4}};

int val = 0;
int
col = numbers[0].length - 2;
for
(int row = 0; row < numbers.length; row++)

{
val
+= numbers[row][col];
}
10
11
12
13
An error occurs
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply