Wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

For Loops and Random Numbers Check for Understanding

Total questions: 10

Worksheet time: 15mins

Name
Class
Date
1.

2

a)

5

b)

7

c)

9

d)

13

e)

20

2.
How many times will the following code print "Welcome to Java"?
int count = 0;
while (count < 10) {
 System.out.println("Welcome to Java");
 count++;
}
a)
8
b)
9
c)
10
d)
0
3.

This loop can only be used when the programmer knows the number of times a code is to be repeated

a)

while

b)

for

c)

do while

d)

repeat until

4.

Which of the following control structure are needed to repeat a code?

a)

sequence

b)

loop

c)

selection

d)

if

5.

FOR loops are

a)

loops which run an unknown number of times

b)

loops which run for a specific number of times

c)

the same as if statements

d)

not part of programming

6.

Which kind of loop would be used?


I need a program that will keep letting me add a monthly payment for 12 months.

a)

FOR Loop

b)

WHILE Loop

7.

How many times does Karel move with this loop?

a)

9

b)

0

c)

10

d)

1

8.

Which command provides a random color?

a)

Randomizer.color

b)

Randomizer.nextColor()

c)

RandColor;

d)

nextColor.Randomizer()

9.

Repeat something 10 times

a)

repeat 10

b)

for (var i=0; i<10; i++)

c)

repeat { } until 10;

d)

while (i = 10)

10.

Which of the following describes numbers that do not follow a pattern?

a)

A. variable numbers

b)

B. flexible numbers

c)

C. random numbers

d)

D. static numbers