wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

While Loops and Boolean Statements

Total questions: 10

Worksheet time: 14mins

Name
Class
Date
1.

int count = 0;

while(count < 10) {

System.out.print(count);

}

a)

0123456789

b)

012345678910

c)

12345678910

d)

It will cause an infinite loop and print out 0 indefinitely.

e)

It will not print anything because the loop body never executes.

2.

int count = 0;

while(count > 10) {

System.out.print(count);

}

a)

0123456789

b)

012345678910

c)

12345678910

d)

It will cause an infinite loop and print out 0 indefinitely.

e)

It will not print anything because the loop body never executes.

3.

int count = 0;

while(count < 10) {

System.out.print(count);

count++;

}

a)

0123456789

b)

012345678910

c)

12345678910

d)

It will cause an infinite loop and print out 0 indefinitely.

e)

It will not print anything because the loop body never executes.

4.

What is printed out?


int num = 10;

num++;

do {

System.out.println("We are the knights who say NI!");

} while(num != 11);

a)

It will print "We are the knights who say NI!" exactly once.

b)

It will not print anything.

c)

It will cause an infinite loop and will print "We are the knights who say NI!" indefinitely.

d)

It will cause an error.

5.

How many times is "Sus" printed out?

int a = 5;

int b = 4;

while((a > b) || (b == a)) {

System.out.println("Sus");

a++;

b+=2;

}

a)

0

b)

1

c)

2

d)

3

e)

Indefinitely because of an infinite loop.

6.

boolean x = true;

boolean y = false;

if (x&&y) {

out.println(x||y);

}

else if (x || y) {

out.println( !(x&&y) );

}

out.println( !(x||y) );

a)

true

true

false

b)

false

true

false

c)

true

false

d)

true

true

e)

false

true

7.

int d=5;

int e=18;

if (d>4 && e>18) {

out.println("joe");

}

else {

out.println("mama");

}

a)

joe

b)

mama

c)

joe

mama

d)

mama

joe

e)

It causes an error.

8.

int e=10;

int f=9;

do{

e--;

f--;

} while(e>6 && f>6);

out.println(e + " - " + f);

a)

10 - 9

b)

It will cause an error.

c)

6 - 8

d)

7 - 6

e)

6 - 6

9.

int g = 10;

int h = 13;

do{

g++;

h--;

}while(g != 13);

out.println(g + " - " + h);

a)

10 - 13

b)

13 - 10

c)

12 - 10

d)

12 - 11

e)

It will cause an error.

10.

String s = "Time is an illusion";

int index = s.length() - 1;

while(index >= 0) {

out.print(s.charAt(index));

index--;

}

a)

Time is an illusion

b)

1817161514131211109876543210

c)

noisulli na si emiT

d)

niul as mT

e)

It will cause an error