Home > Java Programming > Quizzes > Java Basics Practice Test: Control Statements
Java Basics Practice Test: Control Statements
Fast practice, instant feedback. Timer auto-submits when time’s up.
Avg score: 0% Most missed: “Which of the following is not a decision making statement?”
In Java, control statements are used to control the flow of execution in a program. They are used to make decisions, to loop through blocks of code multiple times, and to jump to a different part of the code based on certain conditions.   There are three main types of control statements in Java: Decision-making statements: These statements allow you to make decisions about which block of code to execute based on a condition. The most common decision-making statements are the if, else if, and else statements. Looping statements: These statements allow you to execute a block of code... Show more
Java Basics Practice Test: Control Statements
Time left 00:00
20 Questions

1. Which of these are selection statements in Java?
2. What will be the output of the following Java program?
class comma_operator
{
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}
}
3. What is true about do statement?
4. What would be the output of the following code snippet if variable a=10?
if(a<=0)
{
if(a==0)
{
System.out.println("1 ");
}
else
{
System.out.println("2 ");
}
}
System.out.println("3 ");
5. From where break statement causes an exit?
6. What will be the output of the following Java program?
class comma_operator
{
public static void main(String args[])
{
int sum = 0;
for (int i = 0, j = 0; i < 5 & j < 5; ++i, j = i + 1)
sum += i;
System.out.println(sum);
}
}
7. What is true about a break?
8. Which of these selection statements test only for equality?
9. What is true about do statement?
10. Which of these selection statements test only for equality?
11. The while loop repeats a set of code while the condition is not met?
12. What is the valid data type for variable “a” to print “Hello World”?
switch(a)
{
System.out.println("Hello World");
}
13. Which of the following is used with the switch statement?
14. What will be the output of the following Java program?
class selection_statements
{
public static void main(String args[])
{
int var1 = 5;
int var2 = 6;
if ((var2 = 1) == var1)
System.out.print(var2);
else
System.out.print(++var2);
}
}
15. Which of the following loops will execute the body of loop even when condition controlling the loop is initially false?
16. What will be the output of the following Java program?
class jump_statments
{
public static void main(String args[])
{
int x = 2;
int y = 0;
for ( ; y < 10; ++y)
{
if (y % x == 0)
continue;
else if (y == 8)
break;
else
System.out.print(y + " ");
}
}
}
17. What will be the output of the following Java program?
class Output
{
public static void main(String args[])
{
int a = 5;
int b = 10;
first:
{
second:
{
third:
{
if (a == b >> 1)
break second;
}
System.out.println(a);
}
System.out.println(b);
}
}
}
18. What is the valid data type for variable “a” to print “Hello World”?
switch(a)
{
System.out.println("Hello World");
}
19. Which of these are selection statements in Java?
20. Which of the following is used with the switch statement?