0% found this document useful (0 votes)
14 views

Quiz_ Unit 8_ Lesson 2 - Review Questions

The document contains a quiz with review questions related to programming concepts, specifically focusing on 2D arrays and methods in Java. It includes code segments and asks for outputs or corrections to the code. Each question is worth one point and tests understanding of array manipulation and method functionality.

Uploaded by

clwarren2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views

Quiz_ Unit 8_ Lesson 2 - Review Questions

The document contains a quiz with review questions related to programming concepts, specifically focusing on 2D arrays and methods in Java. It includes code segments and asks for outputs or corrections to the code. Each question is worth one point and tests understanding of array manipulation and method functionality.

Uploaded by

clwarren2007
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

3/13/25, 10:28 AM Quiz: Unit 8: Lesson 2 - Review Questions

Unit 8: Lesson 2 - Review Questions


Started: Mar 13 at 10:28am

Quiz Instructions

Question 1 1 pts

Consider the following code segment.

int[][] array = new int[5][5];


int u = 1;
for (int i = 0; i < array.length; i++)
{
for (int j = 0; j < array[i].length; j++)
{
array[i][j] = u;
u++;
}
}

System.out.println(array[3][3]);

What is printed when this code segment is executed?

20

13

19

18

25

Question 2 1 pts

Suppose data is a 2-d array of Strings that has 5 rows and 5 columns, with initial
contents represented by the following table:

O O X O O
https://courses.projectstem.org/courses/166695/quizzes/8904500/take 1/5
3/13/25, 10:28 AM Quiz: Unit 8: Lesson 2 - Review Questions

O O X X X
O O X O O
O O X X X
O O X O O

Consider the following code segment.

for (int i = 0; i < data.length; i++)


{
for (int j = 0; j < data[i].length; j++)
{
if (data[i][j].equals("O"))
{
data[i][j] = "X";
}
else if (data[i][j].equals("X"))
{
data[i][j] = "O";
}
}
}
for (String[] r : data)
{
for (String s : r)
{
System.out.print(s);
}
System.out.println();
}

Which of the following represents what is printed after the code segment is executed?

XXOXX
XXOOO
XXOXX
XXOOO
XXOXX

OOXOO
OOXXX
OOXOO
OOXXX
OOXOO

OOXOO
XXXOO
OOXOO
XXXOO
OOXOO

https://courses.projectstem.org/courses/166695/quizzes/8904500/take 2/5
3/13/25, 10:28 AM Quiz: Unit 8: Lesson 2 - Review Questions

OOXXX
OOXXX
OOXXX
OOXXX
OOXXX

Question 3 1 pts

Consider the following method which is intended to return a 1-d array containing the
averages of each row in the 2-d array mat.

public static double[] getAverages(double[][] mat)


{
double[] avgs = new double[mat.length];
for (int i = 0; i < mat.length; i++)
{
/* missing code */
}
return avgs;
}

Which of the following should replace /* missing code */ if the method is to work as
intended?

double s = 0;
for (double n : mat[i])
{
s += n;
}
avgs[i] = s / mat.length;

double s = 0;
for (double n : mat)
{
s += n;
}
avgs[i] = s / mat[i].length;

double s = 0;
for (double n : mat[i])
{
s += n;
}
avgs[i] = s;

https://courses.projectstem.org/courses/166695/quizzes/8904500/take 3/5
3/13/25, 10:28 AM Quiz: Unit 8: Lesson 2 - Review Questions

double s = 0;
for (double n : mat[i])
{
s += n;
}
avgs[i] = s / mat[i].length;

double s = 0;
for (double n : mat[i])
{
s += n;
}
avgs[n] = s / mat[n].length;

Question 4 1 pts

Consider the following method.

public static int search(int[][] data, int target)


{
for (int i = 0; i < data.length; i++)
{
for (int j = 0; j < data[i].length; j++)
{
if (data[i][j] == target)
{
return i;
}
}
}
return -1;
}

The following code segment appears in the main method of the same class. What is
printed when this code is executed?

int[][] mat = {{1, 0, 4, 2, 4},


{3, 8, 2, 4, 7}};
System.out.println(search(mat, 4));

https://courses.projectstem.org/courses/166695/quizzes/8904500/take 4/5
3/13/25, 10:28 AM Quiz: Unit 8: Lesson 2 - Review Questions

Not saved Submit Quiz

https://courses.projectstem.org/courses/166695/quizzes/8904500/take 5/5

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy