What is the output of the following code?
int x = 5;
while (true) {
if (x <= 0) break;
System.out.print(x + " ");
x -= 2;
}
Loading test…
12 questions
What is the output of the following code?
int x = 5;
while (true) {
if (x <= 0) break;
System.out.print(x + " ");
x -= 2;
}
What is the output of the following code?
for (int i = 1; i <= 10; i += 3) {
System.out.print(i + " ");
}
How many times does the following loop print "hello"?
for (int i = 0; i < 5; i++) {
System.out.println("hello");
}
What is the output of the following code?
for (int i = 0; i < 3; i++) {
for (int j = i; j < 3; j++) {
System.out.print("* ");
}
System.out.println();
}
What is the output of the following code?
for (int i = 0; i < 5; i++) {
if (i % 2 == 0) continue;
System.out.print(i + " ");
}
What is the output of the following code?
String s = "coding";
int count = 0;
for (int i = 0; i < s.length(); i++) {
if (s.charAt(i) == 'i' || s.charAt(i) == 'o') {
count++;
}
}
System.out.println(count);
What is the output of the following code?
int i = 1;
while (i < 16) {
i *= 2;
}
System.out.println(i);
What is the value of count after the following code executes?
int count = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 3; j++) {
count++;
}
}
What is the output of the following code?
int n = 100;
int count = 0;
while (n > 1) {
n /= 2;
count++;
}
System.out.println(count);
What is the output of the following code?
int x = 1;
do {
System.out.print(x + " ");
x *= 3;
} while (x < 30);
What is the output of the following code?
int sum = 0;
for (int i = 1; i <= 5; i++) {
sum += i;
}
System.out.println(sum);
What is wrong with the following code that is supposed to print numbers 1 through 5?
for (int i = 1; i <= 5; i++) {
System.out.println(i);
if (i == 3) {
i = 5;
}
}