Você está na página 1de 21

CCHS Math Unit 4 (Chapter 7) Test Name: _______________

CS-A (100 Points) 12/8/2013

2 Points / Question

1) Consider the following line of code:

int[] somearray = new int[30];

Which one of the following options is a valid line of code for displaying the twenty-eighth
element of somearray?

a) System.out.println(somearray[28]);
b) System.out.println(somearray(28));
c) System.out.println(somearray(27));
d) System.out.println(somearray[27]);

Answer: d

Title: Which code displays the 28th element of somearray?


Difficulty: Easy

Section Reference 1: 7.1 Arrays

2) Identify the correct statement for defining an integer array named numarray of ten elements.

a) int[] numarray = new int[9];


b) int[] numarray = new int[10];
c) int[10] numarray;
d) int numarray[10];

Answer: b

Title: Which statement defines integer array numarray with ten elements?
Difficulty: Easy

Section Reference 1: 7.1 Arrays

3) Which one of the following statements is a valid initialization of an array named somearray
of ten elements?

a) int[] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
b) int somearray[] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10 };
c) int[10] somearray = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };
d) int somearray[10] = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 };

Answer: a

Unit 4 - Ch 7 Test KEY Page 1 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Title: Which array initialization statement is invalid?


Difficulty: Medium
Section Reference 1: 7.1 Arrays

4) What is the output of the following code snippet?

int[] myarray = { 10, 20, 30, 40, 50 };


System.out.print(myarray[2]);
System.out.print(myarray[3]);

a) 1050
b) 2030
c) 3040
d) 4050

Answer: c

Title: What are values of the elements at the given array indexes?
Difficulty: Medium
Section Reference 1: 7.1 Arrays

5) What is the result of executing this code snippet?

int[] marks = { 90, 45, 67 };


for (int i = 0; i <= 3; i++)
{
System.out.println(marks[i]);
}

a) The code snippet does not give any output.


b) The code snippet displays all the marks stored in the array without any redundancy.
c) The code snippet causes a bounds error.
d) The code snippet executes an infinite loop.

Answer: c

Title: What is output of for loop that traverses given array?


Difficulty: Medium

Section Reference 1: 7.1 Arrays

6) Which one of the following statements is correct about the given code snippet?

int[] somearray = new int[6];


for (int i = 1; i < 6; i++)

Unit 4 - Ch 7 Test KEY Page 2 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

{
somearray[i] = i + 1;
}

a) The for loop initializes all the elements of the array.


b) The for loop initializes all the elements except the first element.
c) The for loop initializes all the elements except the last element.
d) The for loop initializes all the elements except the first and last elements.

Answer: b

Title: Which statement is true about this for loop that initializes an array?
Difficulty: Hard
Section Reference 1: 7.1 Arrays

7) What is the output of the given code snippet?

int[] mynum = new int[5];


for (int i = 1; i < 5; i++)
{
mynum[i] = i + 1;
System.out.print(mynum[i]);
}

a) 2345
b) 1234
c) 1345
d) 1111

Answer: a

Title: What is output of this for loop that traverses/displays array elements?
Difficulty: Medium
Section Reference 1: 7.1 Arrays

8) What is displayed after executing the given code snippet?

int[] mymarks = new int[10];


int total = 0;
Scanner in = new Scanner(System.in);
for (int cnt = 1; cnt <= 10; cnt++)
{
System.out.print("Enter the marks: ");
mymarks[cnt] = in.nextInt();
total = total + mymarks[cnt];
}
System.out.println(total);

a) The code snippet displays the total marks of all ten subjects.

Unit 4 - Ch 7 Test KEY Page 3 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

b) The for loop causes a run-time time error on the first iteration.
c) The code snippet causes a bounds error.
d) The code snippet displays zero.

Answer: c

Title: Which is result of for loop that fills an array and totals its elements?
Difficulty: Hard
Section Reference 1: 7.1 Arrays

9) When an array myArray is only partially filled, how can the programmer keep track of the
current number of elements?

a) access myArray.length()
b) maintain a companion variable that stores the current number of elements
c) access myArray.currentElements()
d) access myArray.length() - 1

Answer: b

Title: How is a partially filled array maintained?


Difficulty: Easy
Section Reference 1: 7.1 Arrays

10) In a partially filled array, the number of slots in the array that are not currently used is

a) the length of the array minus the number of elements currently in the array
b) the number of elements currently in the array minus the length of the array
c) the length of the array plus the number of elements currently in the array
d) the number of elements currently in the array

Answer: a

Title: How do you calculate remaining space in a partially filled array?


Difficulty: Easy
Section Reference 1: 7.1.3 Partially-Filled Arrays

11) What is the result of the following code?

for (double element : values)


{
element = 0;
}

a) The elements of the array values are initialized to zero.

Unit 4 - Ch 7 Test KEY Page 4 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

b) The elements of the array element are initialized to zero.


c) The first element of the array values is initialized to zero.
d) The array values is not modified.

Ans: d

Title: What is the result of the enhanced for loop?


Difficulty: Medium
7.2Section Reference 1: 7.2 The Enhanced for Loop

12) When the order of the elements is unimportant, what is the most efficient way to remove an
element from an array?

a) Delete the element and move each element after that one to a lower index.
b) Replace the element to be deleted with the last element in the array.
c) Replace the element to be deleted with the first element in the array.
d) Replace the element with the next element.

Answer: b

Title: What is the most efficient way to remove an element in an unordered array?
Difficulty: Easy
Section Reference 1: 7.3 Common Array Algorithms
7.3

13) When an array reading and storing input runs out of space

a) the program could be recompiled with a bigger size for the array.
b) the array could be "grown" using the growArray method.
c) it automatically resizes to accommodate new elements.
d) the array could be "grown" using the new command and the copyOf method.

Answer: d

Title: What happens when an array runs out of space?


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

14) It may be necessary to "grow" an array when reading inputs because

a) the number of inputs may not be known in advance.


b) arrays in Java must be resized after every 100 elements.
c) arrays are based on powers of two.
d) the only alternative is a bounds exception.

Unit 4 - Ch 7 Test KEY Page 5 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Answer: a

Title: Why might it be necessary to grow an array when reading inputs?


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

15) The binary search is faster than the linear search, providing

a) the size of the array is a power of two.


b) the elements of the array are ordered.
c) the elements of the array are unordered.
d) the element being searched for is actually in the array.

Answer: b

Title: What is true about the binary search?


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms
Section Reference 2: Special Topic 7.2

16) Which statements about array algorithms are true?

I. The array algorithms are building blocks for many programs that process arrays
II. Java contains ready-made array algorithms for every problem situation
III. It is inefficient to make multiple passes through an array if you can do everything in one pass

a) I, II
b) I, III
c) II, III
d) I, II, III

Answer: b

Title: Which statements about array algorithms are true?


Difficulty: Easy
Section Reference 1: 7.4 Problem Solving: Adapting Algorithms

17.) Suppose you wish to process an array of values and eliminate any potential duplicate values
stored in the array. Which array algorithms might be adapted for this?

a) find the minimum


b) remove an element
c) add an element
d) calculate the sum of the elements

Unit 4 - Ch 7 Test KEY Page 6 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Answer: b

Title: Which array algorithms might be adapted to solve the "remove duplicates" problem?
Difficulty: Medium
Section Reference 1: 7.4 Problem Solving: Adapting Algorithms

18) Which code snippet calculates the sum of all the even elements in an array values?

a)
int sum = 0;
for (int i = 0; i < values.length; i++){
if ((values[i] % 2) == 0){
sum += values[i];
}
}

b)
int sum = 0;
for (int i = 0; i < values.length; i++) {
if ((values[i] % 2) == 0) {
sum++;
}
}
c)
int sum = 0;
for (int i = 0; i < values.length; i++) {
if ((values[i] / 2) == 0) {
sum += values[i];
}
}
d)
int sum = 0;
for (int i = 0; i < values.length; i++) {
if ((values[i] / 2) == 0) {
sum++;
}
}

Answer: a

Title: Which snippet calculates the sum of elements that are even?
Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

19) Which code snippet calculates the sum of all the elements in even positions in an array?

a)
int sum = 0;

Unit 4 - Ch 7 Test KEY Page 7 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

for (int i = 1; i < values.length; i+=2){


sum++;
}
b)
int sum = 0;
for (int i = 0; i < values.length; i++) {
sum++;
}
c)
int sum = 0;
for (int i = 0; i < values.length; i++) {
sum += values[i];
}
d)
int sum = 0;
for (int i = 0; i < values.length; i = i + 2) {
sum += values[i];
}

Answer: d

Title: Which snippet calculates the sum of elements that are in even positions?
Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

20) Java 7 introduced enhanced syntax for declaring array lists, which is termed

a) angle brackets.
b) method lists.
c) diamond syntax.
d) symmetric slants.

Answer: c

Title: What is the term for the syntax Java 7 introduced for declaring array lists?
Difficulty: Easy
Section Reference 1: 7.7 Array Lists

21) Which statements are true regarding the differences between arrays and array lists?

I. Arrays are better if the size of a collection will not change


II. Array lists are more efficient than arrays
III. Array lists are easier to use than arrays

a) I, II
b) I, III

Unit 4 - Ch 7 Test KEY Page 8 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

c) II, III
d) I, II, III

Answer: b

Title: Which statements are true regarding the differences between arrays and array lists?
Difficulty: Medium
Section Reference 1: 7.7 Array Lists

22) What is the value of the count variable after the execution of the given code snippet?

ArrayList<Integer> num = new ArrayList<Integer>();


num.add(1);
num.add(2);
num.add(1);
int count = 0;
for (int i = 0; i < num.size(); i++)
{
if (num.get(i) % 2 == 0)
{
count++;
}
}

a) 1 b) 2 c) 0 d) 3

Answer: a

Title: What is value of count variable after this for loop traverses the array list?
Difficulty: Medium
Section Reference 1: 7.7 Array Lists

23) Consider the following code snippet:

String[] data = { "abc", "def", "ghi", "jkl" };


String [] data2;

In Java 6 and later, which statement copies the data array to the data2 array?

a) data2 = Arrays.copyOf(data, data2.length);


b) data2 = Arrays.copyOf(data, data.length);
c) data2 = Arrays.copyOf(data, data.size());
d) data2 = Arrays.copyOf(data);

Answer: b

Title: Which code is correct to copy from one array to another?

Unit 4 - Ch 7 Test KEY Page 9 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

24) Consider the following code snippet:

String[] data = { "123", "ghi", "jkl", "def", "%&*" };

Which statement sorts the data array in ascending order?

a) data = Arrays.sort();
b) Arrays.sort(data);
c) data = Arrays.sort(data.length);
d) data = Arrays.sort(data);

Answer: b

Title: Which code is correct to sort an array?


Difficulty: Medium

Section Reference 1: 7.3 Common Array Algorithms

25) Consider the following method:

public static int mystery(int length, int n)


{
int[] result = new int[length];
for (int i = 0; i < result.length; i++)
{
result[i] = (int) (n * Math.random());
}
return result;
}

Which statement is correct about the code?

a) The method works perfectly


b) The method returns a random number
c) The method return type should be changed to int[]
d) The method has a bounds error when the array size is too large

Answer: c

Title: What’s true about method that uses array


Difficulty: Medium
.
Section Reference 1: 7.3 Common Array Algorithims

Unit 4 - Ch 7 Test KEY Page 10 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

26) Which one of the following is the correct header for a method named arrMeth that is called
like this:

arrMeth(intArray); // intArray is an integer array of size 3

a) public static void arrMeth(int[] ar, int n)


b) public static void arrMeth(r[], n)
c) public static void arrMeth(int n , int[] ar)
d) public static void arrMeth(int[] ar)

Answer: d

Title: Which method header is valid for the method called in this snippet?
Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

27) Why is the following method header invalid?

public static int[5] meth(int[] arr, int[] num)

a) Methods that return an array cannot specify its size


b) Methods cannot have an array as a return type
c) Methods cannot have an array as a parameter variable
d) Methods cannot have two array parameter variables

Answer: a

Title: Why is the following method signature invalid?


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

28) What is the output of the following code snippet?

public static void main(String[] args) {


String[] arr = { "aaa", "bbb", "ccc" };
mystery(arr);
System.out.println(arr[0] + " " + arr.length);
}
public static void mystery(String[] arr) {
arr = new String[5];
arr[0] = "ddd";
}

a) ddd 5 b) ddd 3 c) aaa 5 d) aaa 3

Unit 4 - Ch 7 Test KEY Page 11 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Answer: d

Title: What is the output after method call that modifies array parameter variable
Difficulty: Hard
Section Reference 1: 7.3 Common Array Algorithims

29) Consider the following code snippet. Which statement should be used to fill in the empty line
so that the output will be [32, 54, 67.5, 29, 35]?

public static void main(String[] args)


{
double data[] = {32, 54, 67.5, 29, 35};
______________
System.out.println(str);
}

a) String str = Arrays.format(data);


b) String str = data.toString();
c) String str = Arrays.toString(data);
d) String str = str + ", " + data[i];

Answer: c

Title: What statement provides the desired output string from array
Difficulty: Hard
Section Reference 1: 7.3 Common Array Algorithms

30) Select the statement that reveals the logic error in the following method.

public static double minimum(double[] data)


{
double smallest = 0.0;
for (int i = 0; i < data.length; i++)
{
if (data[i] < smallest)
{
smallest = data[i];
}
}
return smallest;
}

a) double m = minimum(new double[] { 1.2, -3.5, 6.6, 2.4 });


b) double m = minimum(new double[] { 1.2, 23.5, 16.6, -23.4 });
c) double m = minimum(new double[] { -10.2, 3.5, 62.6, 21.4 });
d) double m = minimum(new double[] { 12.2, 31.5, 6.6, 2.4 });

Unit 4 - Ch 7 Test KEY Page 12 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Answer: d

Title: What statement reveals the logic error of a method using array
Difficulty: Hard
Section Reference 1: 7.3 Common Array Algorithims

31) Consider the following 2-dimensional array. Select the statement that gives the number of
columns in the third row.

int[][] counts =
{
{ 0, 0, 1 },
{ 0, 1, 1, 2 },
{ 0, 0, 1, 4, 5 },
{ 0, 2 }
};

a) int cols = counts[2].size();


b) int cols = counts.length[2];
c) int cols = counts.length;
d) int cols = counts[2].length;

Answer: d

Title: What statement gives the column size of a 2-dimensional array


Difficulty: Hard
Section Reference 1: 7.6 Two-Dimensional Arrays

32) Consider the following code snippet:

int cnt = 0;
int[][] numarray = new int[2][3];
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 2; j++)
{
numarray[j][i] = cnt;
cnt++;
}
}

What is the value of numarray[1][2] after the code snippet is executed?

a) 2 b) 5 c) 3 d) 4

Answer: b

Unit 4 - Ch 7 Test KEY Page 13 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Title: What is the value of this 2-dimension array element after the nested for loop is executed?
Difficulty: Hard
Section Reference 1: 7.6 Two-Dimensional Arrays

33) Which one of the following statements is the correct definition for a two-dimensional array
of 20 rows and 2 columns of the type integer?

a) int[][] num = new int[20][2];


b) int[][] num = new int[2][20];
c) int[][] num = new int[20,2];
d) int[][] num = new int[2,20];

Answer: a

Title: Which is correct definition for a 2D integer array of 20 rows and 2 columns?
Difficulty: Medium

Section Reference 1: 7.6 Two-Dimensional Arrays

34) Consider the following code snippet:

int[][] numarray =
{
{ 3, 2, 3 },
{ 0, 0, 0 }
};
System.out.print(numarray[0][0]);
System.out.print(numarray[1][0]);

What is the output of the given code snippet?

a) 00 b) 31 c) 30 d) 03

Answer: c

Title: What is output of snippet that initializes 2-dimensional array and displays two of its
elements?
Difficulty: Hard
Section Reference 1: 7.6 Two-Dimensional Arrays

35) Which one of the following statements is correct for displaying the value in the second row
and the third column of a two-dimensional, size 3 by 4 array?

a) System.out.println(arr[1][2]);
b) System.out.println(arr[2][3]);
Unit 4 - Ch 7 Test KEY Page 14 of 21
CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

c) System.out.println(arr[2][1]);
d) System.out.println(arr[3][2]);

Answer: a

Title: Which statement displays the value in the second row and third column of a 2-dimensional
3 by 4 array?
Difficulty: Medium
Section Reference 1: 7.6 Two-Dimensional Arrays

36) Consider the following code snippet:

ArrayList<Integer> num1 = new ArrayList<Integer>();


int data;
Scanner in = new Scanner(System.in);
for (int i = 0; i < 5; i++)
{
data = in.nextInt();
num1.add(data);
if (data == 0 && num1.size() > 3)
{
num1.remove(num1.size() - 1);
}
}
System.out.println("size is : " + num1.size());

What is the output of the given code snippet if the user enters 1,2,0,0,1 as the input?

a) size is : 1 b) size is : 2 c) size is : 4 d) size is : 0

Answer: c

Title: What is the size of the array list after for loop with given input values?
Difficulty: Medium
Section Reference 1: 7.7 Array Lists

37) What is the output of the following code snippet?

ArrayList<Integer> num;
num.add(4);
System.out.println(num.size());

a) 1
b) 0
c) 4
d) Error because num is not initialized

Unit 4 - Ch 7 Test KEY Page 15 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Answer: d

Title: What is value of array list.size after this snippet with add()?
Difficulty: Easy
Section Reference 1: 7.7 Array Lists

38) What is the value of the cnt variable after the execution of the code snippet below?

ArrayList<Integer> somenum = new ArrayList<Integer>();


somenum.add(1);
somenum.add(2);
somenum.add(1);
int cnt = 0;
for (int index = 0; index < somenum.size(); index++)
{
if (somenum.get(index) % 2 == 0)
{
cnt++;
}
}

a) 1 b) 2 c) 3 d) 0

Answer: a

Title: What is value of cnt variable after this for loop traverses the array list?
Difficulty: Medium
Section Reference 1: 7.7 Array Lists

39) What is the value of myArray[1][2] after this code snippet is executed?

int count = 0;
int[][] myArray = new int[4][5];
for (int i = 0; i < 5; i++)
{
for (int j = 0; j < 4; j++)
{
myArray[j][i] = count;
count++;
}
}

a) 8 b) 9 c) 19 d) 11

Answer: b

Title: What is the value of this 2-dimensional array element after the nested for loop is executed?

Unit 4 - Ch 7 Test KEY Page 16 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Difficulty: Hard
Section Reference 1: 7.6 Two-Dimensional Arrays

40) What is the output of the code snippet below?

int[][] numarray =
{
{ 8, 7, 6 },
{ 0, 0, 0 }
};
System.out.print(numarray[0][0]);
System.out.print(numarray[1][0]);

a) 00 b) 87 c) 80 d) 08

Answer: c

Title: What is output of snippet that initializes 2-dimensional array and displays two of its
elements?
Difficulty: Hard
Section Reference 1: 7.6 Two-Dimensional Arrays

41) Consider the following code snippet:

int[][] arr =
{
{ 1, 2, 3, 0 },
{ 4, 5, 6, 0 },
{ 0, 0, 0, 0 }
};
int[][] arr2 = arr;
System.out.println(arr2[2][1] + arr2[1][2]);

What is the output of the given code snippet on execution?

a) 5 b) 6 c) 7 d) 9

Answer: b

Title: What is the output of this snippet that sums two values in a copied 2-dimensional array
reference?
Difficulty: Medium
Section Reference 1: 7.6 Two-Dimensional Arrays

42) What should you check for when calculating the smallest value in an array list?

Unit 4 - Ch 7 Test KEY Page 17 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

a) The array list contains at least one element.


b) The array list contains at least two elements.
c) The array list contains the maximum value in the first element.
d) The array list contains the minimum value in the first element.

Answer: a

Title: What should be checked when calculating the smallest value in an array list?
Difficulty: Easy
Section Reference 1: 7.7 Array Lists

43) Which one of the following is the correct code snippet for calculating the largest value in an
integer array list aList?

a)
int max = 0;
for (int count = 1; count < aList.size(); count++) {
if (aList.get(count) > max) {
max = aList.get(count);
}
}
b)
int max = aList.get(0);
for (int count = 1; count < aList.size(); count++) {
if (aList.get(count) > max) {
max = aList.get(count);
}
}
c)
int max = aList[1];
for (int count = 1; count < aList.size(); count++) {
if (aList.get(count) > max) {
max = aList.get(count);
}
}
d)
int max = aList.get(0);
for (int count = 1; count > aList.size(); count++) {
if (aList.get(count) >= max) {
max = aList.get(count);
}
}

Answer: b

Title: Which is correct code for calculating the largest value in array list of size 6?
Difficulty: Medium
Section Reference 1: 7.7 Array Lists

Unit 4 - Ch 7 Test KEY Page 18 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

44) What is the output of the following code?


int[][] counts =
{
{ 0, 0, 1 },
{ 0, 1, 1, 2 },
{ 0, 0, 1, 4, 5 },
{ 0, 2 }
};
System.out.println(counts[3].length);

a) 2 b) 3 c) 4 d) 5

Answer: a

Title: What is the output of the code with a 2-dimensional array having different column sizes
Difficulty: Hard
Section Reference 1: 7.6 Two-Dimensional Arrays

45) Assume the following variable has been declared and given a value as shown:

int[] numbers = {9, 17, -4, 21 };

Which is the value of numbers.length?

a)3 b)4 c)9 d)21

Answer: b

Title: Which is the value of numbers.length


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

46) Assume the variable numbers has been declared to be an array that has at least one
element. Which is the following represents the last element in numbers?
a)numbers[numbers.length]
b)numbers.length
c)numbers[–1]
d)numbers[numbers.length – 1]

Answer: d

Unit 4 - Ch 7 Test KEY Page 19 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

Title: Which is the following represents the last element in numbers


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

47) What will be printed by the statements below?

int[] values = { 1, 2, 3, 4};


values[2] = 24;
values[values[0]] = 86;
for (int i = 0; i < values.length; i++)
System.out.print (values[i] + " ");

a)86 2 24 4
b)86 24 3 4
c)1 86 24 4
d)1 2 24 86

Answer: c

Title: What will be printed by the statements below


Difficulty: Medium
Section Reference 1: 7.3 Common Array Algorithms

48) What will be printed by the statements below?

int[] values = { 4, 5, 6, 7};


for (int i = 1; i < values.length; i++)
values[i] = values[i – 1] + values[i];
for (int i = 0; i < values.length; i++)
System.out.print (values[i] + " ");

a)4 9 11 13
b)4 9 15 22
c)9 11 13 7
d)4 5 6 7

Answer: b

Title: What will be printed by the statements below


Section Reference 1: 7.6 Two-Dimensional Arrays
Difficulty: Medium

Unit 4 - Ch 7 Test KEY Page 20 of 21


CCHS Math Unit 4 (Chapter 7) Test Name: _______________
CS-A (100 Points) 12/8/2013

49) What will be printed by the statements below?

int[] values = { 4, 5, 6, 7};


values[0] = values[3];
values[3] = values[0];
for (int i = 0; i < values.length; i++)
System.out.print (values[i] + " ");

a)7 5 6 4
b)7 6 5 4
c)7 5 6 7
d)4 5 6 4

Answer: c

Title: What will be printed by the statements below


Section Reference 1: 7.6 Two-Dimensional Arrays
Difficulty: Medium

50) What will be printed by the statements below?

int[] values = { 10, 24, 3, 64};


int position = 0;
for (int i = 1; i < values.length; i++)
if (values[i] > values[position])
position = i;
System.out.print (position);

a)0
b)1
c)2
d)3

Answer: d

Title: What will be printed by the statements below


Section Reference 1: 7.6 Two-Dimensional Arrays
Difficulty: Medium

Unit 4 - Ch 7 Test KEY Page 21 of 21

Você também pode gostar