wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

PreTrainingScannerLoops

Total questions: 10

Worksheet time: 8mins

Name
Class
Date
1.

How many times does the pictured loop iterate?

(not the number of lines)

a)

99

b)

98

c)

100

d)

0

2.

in a while or do-while loop, what comes directly after the while keyword?

a)

curly braces

b)

a semicolon

c)

a condition that evaluates to true or false, enclosed in parentheses

d)

a variable to check against

3.

Which loop always executes at least once?

a)

Fruit Loop

b)

for loop

c)

do-while loop

d)

while loop

4.

What method should be called when you are done using a Scanner object?

a)

close()

b)

end()

c)

done()

d)

finish()

5.

Which of the following is NOT a type of loop in Java?

a)

for-in

b)

do-while

c)

for

d)

while

6.

True/False: a for-each loop can be reversed to iterate from the last index of an array to the first

a)

True

b)

False

7.

Given the pictured loop, what is the equivalent for loop?

a)

for(int i=0; i++; i<5){}

b)

for(int i=0; i<5){

i++;

}

c)

for(int i=0; i<5; i++){}

8.

True/False: if the condition for a while loop is false, the loop will be skipped

a)

True

b)

False

9.

What package needs to be imported to use Scanner?

a)

java.util.*

b)

java.awt

c)

java.io.InputStream

d)

java.util.scanner.*

10.

True/False: the pictured loop will result in an ArrayIndexOutOfBoundsException

a)

True

b)

False