wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

MK Java for-Loop Quiz 2

Total questions: 10

Worksheet time: 5mins

Name
Class
Date
1.

To execute a for-loop the condition must be true in the beginning.

a)

True

b)

False

2.

The for-loop is an exit-controlled loop.

a)

True

b)

False

3.

Which of the following is not a loop in Java?

a)

while

b)

for

c)

repeat-until

d)

do-while

4.

Which of the following is not a jump statement in Java?

a)

return

b)

break

c)

continue

d)

goto

5.

Which of the following is an exit-controlled loop?

a)

while

b)

for

c)

do-while

d)

repeat-until

6.

How many times will the following code print "Hello"?

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

{

System.out.println("Hello");

}

a)

0

b)

7

c)

6

d)

1

7.

What value of sum will be printed for the following piece of code:


int sum = 0;

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

{

sum = i;

}

System.out.println(sum);

a)

0

b)

1

c)

4

d)

5

e)

10

8.

What value of adder will be printed for the following piece of code:

int adder = 0;

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

{

adder += i;

}

System.out.println(adder);

a)

0

b)

5

c)

10

d)

15

9.

How many times will the following loop execute and what value of sum will be displayed? TWO ANSWERS are to be checked.


int add = 10;

for (int i = 1; i > 5; i++)

{

add+=i;

}

System.out.println(add);

a)

15

b)

25

c)

10

d)

0

e)

5

10.

What will be the value of d at the end of execution of the following piece of code?

int d = 1;

for(int i = 2; i <=5; i++)

{

d = d * i;

}

System.out.println(d);

(a)