wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Arrays += Chan

Total questions: 12

Worksheet time: 2hrs 2mins

Name
Class
Date
1.

Given the following code segment what will be returned when you execute: getIndexOfLastElementSmallerThanTarget(values,-13);

a)

A. -1

b)

B. -15

c)

C. 1

d)

D. You will get an out of bounds error.

2.

Given the following code segment what would be the elements of a when you execute: doubleLast();

a)

A. {-40, -30, 4, 16, 32, 66}

b)

B. {-40, -30, 4, 8, 16, 32}

c)

C. {-20, -15, 2, 16, 32, 66}

d)

D. {-20, -15, 2, 8, 16, 33}

3.

What is returned from mystery when it is passed {10, 30, 30, 60}?

a)

A. 17.5

b)

B. 30.0

c)

C. 130

d)

D. 32

e)

E. 32.5

4.

What is the output of the code segment?

(a)  

5.

Select all missing code that works.

a)

int i = ans.length; i >= 0; i--

b)

int i = ans.length-1; i >= 0; i--

c)

int i = ans.length-1; i > 0; i--

d)

int i = 0; i < ans.length; i++

e)

int i = 0; i <= ans.length; i++

6.

Given an array of length 5, what are the indexes of the middle three elements?

a)

4

b)

2

c)

1

d)

0

e)

3

7.

Given an array of length 3, called arr, what is the middle element?

a)

arr[1]

b)

2

c)

1

d)

arr[2]

8.

Select all options that would give you an error.

Assume the Zoog and the Car objects have working class definitions.

a)

float[] numbers = new float[5 + 6];

b)

int num = 5; float[] numbers = new int[num];

c)

int num = (5 * 6)/2; float[] numbers = new float[num = 5];

d)

int num = 5; Zoog[] zoogs = new Zoog[num * 10];

e)

float num = 5.2; Car[] cars = new Car[num];

9.

What is the output of the given code segment

a)

2

b)

-12

c)

-3

d)

None of the above

10.

What is the output of the given code segment?

a)

Null Pointer Exception

b)

3

c)

2

d)

0

11.

How many objects have been instantiated?

a)

22

b)

33

c)

11

d)

44

e)

None of the above.

12.

Which of the following creates an array of 10 doubles called prices?

a)

A. int[] prices = new int[10];

b)

B. double[] prices = new double[10];

c)

C. double[] prices;

d)

D. double[10] prices = new double[];