subject

Consider the following code segment. int[][] arr = {{3, 2, 1}, {4, 3, 5}};
for (int row = 0; row < arr. length; row++)
{
for (int col = 0; col < arr[row].length; col++)
{
if (col > 0)
{
if (arr[row][col] >= arr[row][col - 1])
{
System. out. println("Condition one");
}
}
if (arr[row][col] % 2 == 0)
{
System. out. println("Condition two");
}
}
}
As a result of executing the code segment, how many times are "Condition one" and "Condition two" printed?
A. "Condition one" is printed twice, and "Condition two" is printed twice.
B. "Condition one" is printed twice, and "Condition two" is printed once.
C. "Condition one" is printed once, and "Condition two" is printed twice.
D. "Condition one" is printed once, and "Condition two" is printed once.
E. "Condition one" is never printed, and "Condition two" is printed once.
2. Consider the following code segment.
int[][] arr = {{1, 3, 4}, {4, 5, 3}};
int max = arr[0][0];
for (int row = 0; row < arr. length; row++){
for (int col = 0; col < arr[row].length; col++)
{
int temp = arr[row][col];
if (temp % 2 == 0)
{
arr[row][col] = temp + 1; // line 11
}
if (temp > max)
{
max = temp;
}
}
}
System. out. println(max);
How many times will the statement in line 11 be executed as a result of executing the code segment?
A. 2
B. 3
C. 4
D. 5
E. 6
3. Consider the following method, sumRows, which is intended to traverse all the rows in the two-dimensional (2D) integer array num and print the sum of all the elements in each row.
public static void sumRows(int[][] num)
{
for (int[] r : num)
{
int sum = 0;
for (int j = 0; j < num. length; j++)
{
sum += r[j];
}
System. out. print(sum + " ");
}
}
For example, if num contains {{3, 5}, {6, 8}}, then sumRows(num) should print "8 14 ".
The method does not always work as intended. For which of the following two-dimensional array input values does sumRows NOT work as intended?
A. {{0, 1}, {2, 3}}
B. {{10, -18}, {48, 17}}
C. {{-5, 2, 0}, {4, 11, 0}}
D. {{4, 1, 7}, {-10, -11, -12}}
E. {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 23.06.2019 04:31
Cloud computing service providers manage different computing resources based on the services they offer. which resources do iaas and paas providers not manage? iaas providers do not manage the for the client, whereas paas providers usually do not manage the for their clients. iaas- storage server operating system network paas- applications interafce storage vertualiation
Answers: 2
question
Computers and Technology, 23.06.2019 14:00
Technician a says that with self-adjusting clutch systems, the release bearing constantly rotates. technician b says that the ball bearing portion of the release bearing should be lubricated with high-temperature grease during routine maintenance. which technician is correct?
Answers: 2
question
Computers and Technology, 24.06.2019 13:00
Think of a spreadsheet as a giant calculator spread of paper chart data collector
Answers: 2
question
Computers and Technology, 24.06.2019 15:30
George is working as a programming team lead. which statements correctly describe the skills that he requires?
Answers: 3
You know the right answer?
Consider the following code segment. int[][] arr = {{3, 2, 1}, {4, 3, 5}};
for (int row = 0;...
Questions
question
Mathematics, 12.07.2021 06:40
question
English, 12.07.2021 06:50
question
Mathematics, 12.07.2021 06:50
question
Social Studies, 12.07.2021 06:50
question
Business, 12.07.2021 06:50
Questions on the website: 13722360