WorksheetsJava Loops
Total questions: 10
Worksheet time: 5mins
Name
Class
Date
1.
How many stars are printed?
a)
7
b)
3
c)
4
d)
5
e)
Infinite Loop
2.
In total, how many times is the inner loop executed?
a)
5
b)
10
c)
15
d)
50
e)
Infinite Loop
3.
How many times does the loop print a *
a)
40
b)
20
c)
24
d)
30
e)
Infinite Loop
4.
What does the following code print?
a)
A rectangle of 8 rows with 5 stars per row
b)
A rectangle of 8 rows with 4 stars per row
c)
A rectangle of 6 rows with 5 stars per row
d)
A rectangle of 6 rows with 4 stars per row
e)
Infinite Looo
5.
What does the following code print?
a)
5 6 7 8 9
b)
4 5 6 7 8 9 10 11 12
c)
3 5 7 9 11
d)
3 4 5 6 7 8 9 10 11 12
6.
True/False
If a loop condition is never satisfied then the loop does not execute.
If a loop condition is never satisfied then the loop does not execute.
a)
True
b)
False
7.
What does this block of code do?
for( int i = 0; i < 10; i++)
out.println("hello");
for( int i = 0; i < 10; i++)
out.println("hello");
a)
Prints the String "hello" ten times.
b)
Prints the String "hello"
c)
Heebee Jeebies
d)
Nothing. The code does not run.
8.
Which of the loop types below IS NOT recognized in Java.
a)
while
b)
do-while
c)
for
d)
repeat
9.
What is the loop condition for this code?
for(int i = 0; i <= 3; i++)
out. print("sup");
for(int i = 0; i <= 3; i++)
out. print("sup");
a)
int i = 0
b)
i <= 3
c)
i++
d)
out.print("sup")
10.
What will be the output of the following Java code?
class operators {
public static void main(String args[]) {
int x = 8;
System.out.println(++x * 3 + " " + x); }
}
a)
24 8
b)
24 9
c)
27 9
d)
27 8
100 %
