Java Control Flow Statements code Quiz

Java Control Flow Statements Code Quiz

This quiz is designed to test your understanding of control flow statements in Java. Control flow statements are fundamental to programming, as they determine the flow of execution based on certain conditions.

Good Luck!
Get ready to put your Java skills to the test and gain a deeper understanding of control flow statements. Let’s start the quiz and see how well you know Java control flow!

1 / 25

What will be the output of the following code?

int x = 0;
int y = 10;
do {
y–;
++x;
} while(x < 5);
System.out.println(x + “, ” + y);

2 / 25

What will be the output of the following code?

int x = 1;
int y = 2;
if(x == 1) {
if(y == 2) {
System.out.println(“x is 1 and y is 2”);
} else {
System.out.println(“x is 1 and y is not 2”);
}
} else {
System.out.println(“x is not 1”);
}

3 / 25

Which of the following statements about the continue statement in Java is true?

4 / 25

What will be the output of the following code?

int x = 10;
if (x > 0) {
System.out.println(“Positive”);
} else if (x < 0) {
System.out.println(“Negative”);
} else {
System.out.println(“Zero”);
}

5 / 25

What will be the output of the following code?

int num = 10;
switch(num) {
case 5:
System.out.println(“Five”);
break;
case 10:
System.out.println(“Ten”);
break;
case 15:
System.out.println(“Fifteen”);
break;
default:
System.out.println(“Default”);
}

6 / 25

What will be the output of the following code?

int count = 0;
while(count < 5) {
count++;
if(count == 3) {
continue;
}
System.out.println(“Count is: ” + count);
}

7 / 25

What will be the output of the following code?

int x = 0;
for(int i = 1; i <= 3; i++) {
for(int j = 1; j <= 3; j++) {
if(i * j % 2 == 0) {
continue;
}
x += i * j;
}
}
System.out.println(x);

8 / 25

What will be the output of the following code?

int a = 5, b = 10;
if(a > b) {
System.out.println(“a is greater than b”);
} else {
System.out.println(“a is less than or equal to b”);
}

9 / 25

What will be the output of the following code?

int count = 0;
for(int i = 0; i < 10; i++) {
if(i % 2 == 0) {
continue;
}
count++;
}
System.out.println(count);

10 / 25

What will be the output of the following code?

for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
System.out.println(i + ” is even”);
} else {
System.out.println(i + ” is odd”);
}
}

11 / 25

What will be the output of the following code?

int i = 5;
while(i < 10) {
System.out.println(i);
if(i == 7) {
break;
}
i++;
}

12 / 25

What is the purpose of a default case in a switch statement?

13 / 25

What will be the output of the following code?

int n = 1;
while(n < 5) {
if(n % 2 == 0) {
n++;
continue;
}
System.out.println(n);
n++;
}

14 / 25

What will be the output of the following code?

int x = 10;
if (x % 2 == 0) {
if (x % 3 == 0) {
System.out.println(“Divisible by 2 and 3”);
} else {
System.out.println(“Divisible by 2 but not by 3”);
}
} else {
System.out.println(“Not divisible by 2”);
}

15 / 25

What will be the output of the following code?

int num = 2;
switch(num) {
case 1:
System.out.println(“One”);
case 2:
System.out.println(“Two”);
default:
System.out.println(“Default”);
}

16 / 25

What will be the output of the following code?

int i = 1;
while(i <= 3) {
switch(i) {
case 1:
System.out.println(“One”);
break;
case 2:
System.out.println(“Two”);
break;
case 3:
System.out.println(“Three”);
break;
}
i++;
}

17 / 25

What will be the output of the following code?

int count = 0;
for(int i = 0; i < 5; i++) {
if(i % 2 == 0) {
count++;
}
}
System.out.println(count);

18 / 25

What will be the output of the following code?

int i = 0;
do {
System.out.println(i);
i++;
} while(i < 3);

19 / 25

Which of the following statements about the return statement in Java is true?

20 / 25

Which of the following statements will correctly print numbers from 1 to 5 in Java?

21 / 25

What will be the output of the following code?

for(int i = 0; i < 5; i++) {
if(i == 2) {
break;
}
System.out.println(i);
}

22 / 25

What will be the output of the following code?

int i = 5;
while(i > 0) {
if(i == 3) {
i–;
continue;
}
System.out.println(i);
i–;
}

23 / 25

What will be the output of the following code?

int num = 2;
switch(num) {
case 1:
System.out.println(“One”);
case 2:
System.out.println(“Two”);
case 3:
System.out.println(“Three”);
break;
default:
System.out.println(“Default”);
}

24 / 25

What will be the output of the following code?

int count = 0;
for(int i = 0; i < 3; i++) {
for(int j = 0; j < 2; j++) {
if(i == 1 && j == 1) {
break;
}
count++;
}
}
System.out.println(“Count is: ” + count);

25 / 25

What will be the output of the following code?

int x = 5;
for(int i = 0; i < x; i++) {
if(i % 2 == 0) {
continue;
}
System.out.println(i);
}

Your score is

The average score is 0%

0%

Exit

Leave a Reply