NEW
Font size
WorksheetsWhile Loops and Boolean Statements
Total questions: 10
Worksheet time: 14mins
int count = 0;
while(count < 10) {
System.out.print(count);
}
0123456789
012345678910
12345678910
It will cause an infinite loop and print out 0 indefinitely.
It will not print anything because the loop body never executes.
int count = 0;
while(count > 10) {
System.out.print(count);
}
0123456789
012345678910
12345678910
It will cause an infinite loop and print out 0 indefinitely.
It will not print anything because the loop body never executes.
int count = 0;
while(count < 10) {
System.out.print(count);
count++;
}
0123456789
012345678910
12345678910
It will cause an infinite loop and print out 0 indefinitely.
It will not print anything because the loop body never executes.
What is printed out?
int num = 10;
num++;
do {
System.out.println("We are the knights who say NI!");
} while(num != 11);
It will print "We are the knights who say NI!" exactly once.
It will not print anything.
It will cause an infinite loop and will print "We are the knights who say NI!" indefinitely.
It will cause an error.
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;
}
0
1
2
3
Indefinitely because of an infinite loop.
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) );
true
true
false
false
true
false
true
false
true
true
false
true
int d=5;
int e=18;
if (d>4 && e>18) {
out.println("joe");
}
else {
out.println("mama");
}
joe
mama
joe
mama
mama
joe
It causes an error.
int e=10;
int f=9;
do{
e--;
f--;
} while(e>6 && f>6);
out.println(e + " - " + f);
10 - 9
It will cause an error.
6 - 8
7 - 6
6 - 6
int g = 10;
int h = 13;
do{
g++;
h--;
}while(g != 13);
out.println(g + " - " + h);
10 - 13
13 - 10
12 - 10
12 - 11
It will cause an error.
String s = "Time is an illusion";
int index = s.length() - 1;
while(index >= 0) {
out.print(s.charAt(index));
index--;
}
Time is an illusion
1817161514131211109876543210
noisulli na si emiT
niul as mT
It will cause an error
