unit 8 Review csa test

unit 8 Review csa test

Professional Development

36 Qs

quiz-placeholder

Similar activities

C# Skill Review

C# Skill Review

12th Grade - Professional Development

32 Qs

Javascript

Javascript

Professional Development

32 Qs

C pro test

C pro test

8th Grade - Professional Development

35 Qs

WP CHAPTER1 TO 3

WP CHAPTER1 TO 3

Professional Development

32 Qs

Java Screening Test

Java Screening Test

Professional Development

40 Qs

polymorphism, exception and packages

polymorphism, exception and packages

Professional Development

40 Qs

Java Control Structures

Java Control Structures

11th Grade - Professional Development

39 Qs

InCube Quiz #1

InCube Quiz #1

Professional Development

31 Qs

unit 8 Review csa test

unit 8 Review csa test

Assessment

Quiz

Computers

Professional Development

Easy

Created by

Jeff Cougger

Used 5+ times

FREE Resource

36 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following method, count, which is intended to traverse all the elements in the two-dimensional (2D) String array things and return the total number of elements that contain at least one "a".

public static int count(String[][] things)
{
int count = 0;
for (int r = 0; r < things.length; r++)
{
for (int c = 0; c < things[r].length - 1; c++)
{
if (things[r][c].indexOf("a") >= 0)
{
count++;
}
}
}
return count;
}

For example, if things contains {{"salad", "soup"}, {"water", "coffee"}}, then count(things) should return 2.

The method does not always work as intended. For which of the following two-dimensional array input values does count NOT work as intended?

{{"lemon"}, {"lime"}}

{{"tall", "short"}, {"up", "down"}}

{{"rabbit", "bird"}, {"cat", "dog"}, {"gecko", "turtle"}}

{{"scarf", "gloves", "hat"}, {"shoes", "shirt", "pants"}}

{{"math", "english", "physics"}, {"golf", "baseball", "soccer"}}

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following method, which is intended to return the element of a 2-dimensional array that is closest in value to a specified number, val.

/* @return the element of 2-dimensional array mat whose value is closest to val /
public double findCloset(double[][] mat, double val)
{
double answer = mat[0][0];
double minDiff = Math.abs(answer - val);
for (double[] row : mat)
{
for (double num : row)
{
answer = num;
minDiff = Math.abs(num - val);
}
}
}
return answer;
}
Which of the following could be used to replace / missing / so that findClosest will work as intended?

val - row[num] < minDiff

Math.abs(num - minDIff) < minDiff

val - num < 0.0

Math.abs(num - val) < minDiff

Math.abs(row[num] - val) < minDiff

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

A two-dimensional array myArray is to be created with the following contents.

{{0, 0, 3},
{0, 0, 0},
{7, 0, 0}}

Which of the following code segments can be used to correctly create and initialize myArray?

I.
int myArray[][] = new int[3 [3];
myArray[0][2] = 3;
myArray[2][0] = 7;

II.
int myArray[][] = new int[3][3];myArray[0][2] = 7;myArray[2][0] = 3;

III.
int myArray[][] = {{0, 0, 3}, {0, 0, 0}, {7, 0, 0}};

I only

II only

III only

I and III

II and III

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.

int[][] mat = new int[3][4];
for (int row = 0; row < mat.length; row++)
{
for (int col = 0; col < mat[0].length; col++)
{
if (row < col)
{
mat[row][col] = 1;
}
else if (row == col)
{
mat[row][col] = 2;
}
else
{
mat[row][col] = 3;
}
}
}

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

{{2, 1, 1},
{3, 2, 1},
{3, 3, 2},
{3, 3, 3}}

{{2, 3, 3},
{1, 2, 3},
{1, 1, 2},
{1, 1, 1}}

{{2, 3, 3, 3},
{1, 2, 3, 3},
{1, 1, 2, 3}}

{{2, 1, 1, 1},
{3, 2, 1, 1},
{3, 3, 2, 1}}

{{1, 1, 1, 1},
{2, 2, 2, 2},
{3, 3, 3, 3}}

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.

int[][] mat = {{10, 15, 20, 25},
{30, 35, 40, 45},
{50, 55, 60, 65}};
for (int[] row : mat)
{
for (int j = 0; j < row.length; j += 2)
{
System.out.print(row[j] + " ");
}
System.out.println();
}

What, if anything, is printed as a result of executing the code segment?

10 15 20 25
50 55 60 65

10 20
30 40
50 60

10 15 20 35
30 35 40 45
50 55 60 65

Nothing is printed, because an ArrayIndexOutOfBoundsException is thrown.

Nothing is printed, because it is not possible to use an enhanced for loop on a two-dimensional array.

6.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

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?

"Condition one" is printed twice, and "Condition two" is printed twice.

"Condition one" is printed twice, and "Condition two" is printed once.

"Condition one" is printed once, and "Condition two" is printed twice.

"Condition one" is printed once, and "Condition two" is printed once.

"Condition one" is never printed, and "Condition two" is printed once.

7.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Consider the following code segment.

int[][] points = {{11, 12, 13, 14, 15},

{21, 22, 23, 24, 25},

{31, 32, 33, 34, 35},

{41, 42, 43, 44, 45}};

for (int row = 0; row < points.length; row++)

{

for (int col = points[0].length - 1; col >= row; col--)

{

System.out.print(points[row][col] + " ");

}

System.out.println();

}

What is printed when this code segment is executed?

15 14

25 24 23

35 34 33 32

45 44 43 42 41

15 14 13 12

25 24 23

35 34

45

11 12 13 14 15

21 22 23 24

31 32 33

41 42

15 14 13 12 11

25 24 23 22

35 34 33

45 44

15 14 13 12 11

25 24 23 22 21

35 34 33 32 31

45 44 43 42 41

Create a free account and access millions of resources

Create resources
Host any resource
Get auto-graded reports
or continue with
Microsoft
Apple
Others
By signing up, you agree to our Terms of Service & Privacy Policy
Already have an account?