Get Job-ready: Java Course with 45+ Real-time Projects! - Learn Java
Put your decision-making skills to the test with this comprehensive quiz on one of Java’s most essential concepts! Whether you’re a budding coder or a seasoned developer, this engaging challenge will help you solidify your understanding of conditional statements, control the flow of your programs, and make confident coding choices.
Delve into questions that explore if statements, else clauses, nested conditions, and more. Gear up to tackle different scenarios and make Java work for you!
Time limit: 0
Quiz Summary
0 of 15 Questions completed
Questions:
Information
You have already completed the quiz before. Hence you can not start it again.
Which of the following is the right syntax for a nested if loop ?
Correct
Incorrect
Question 4 of 15
4. Question
class Sample {
public static void main ( String args [ ] )
{
int a = 4 ;
if( a < 10 ) {
if ( a < 5 ) {
system.out.println(“The number is also less than 5 “);
}else {
system.out.println(“The number is less than 10 alone “);
}
Correct
Incorrect
Question 5 of 15
5. Question
If the input value from the user does not match with any case statements in the switch case , which block of statement will be executed ?
Correct
Incorrect
Question 6 of 15
6. Question
class SwitchExample {
public static void main ( String args [ ] )
{
int a = 5 ;
switch(a)
{
case 5:
{
system.out.println(“Number is 5 “);
}
case 6:
{
system.out.println(“Number is not a 5 “);
}
Default:
{
system.out.println(“It is an unknown number”);
}
}
}
}
Correct
Incorrect
Question 7 of 15
7. Question
class Demo {
public static void main ( String args [ ] )
{
int x = 0;
switch(x)
{
case 0 :
{
system.out.println(“The number is 0 “);
break;
}
case 1:
{
system.out.println(“The number is not zero “);
break;
}
}
}
}
Correct
Incorrect
Question 8 of 15
8. Question
Which of the following is true about the switch case ?
Correct
Incorrect
Question 9 of 15
9. Question
class SwitchCaseSample {
public static void main ( String args [ ] )
{
float pi = 3.14;
switch(pi)
{
case 3.14:
{
system.out.println(“This is the value of PI “);
break;
}
default:
{
system.out.println(“This is not the value of PI”);
break;
}
}
}
}
Correct
Incorrect
Question 10 of 15
10. Question
Which of the following is the correct syntax of a switch case in Java ?
Correct
Incorrect
Question 11 of 15
11. Question
class ReturnStatement {
public static void main ( String args [ ] )
{
int a = 10;
if(a == 10) {
system.out.println(a);
return;
++a;
system.out.println(a);
}
}
}
Correct
Incorrect
Question 12 of 15
12. Question
class ContinueStatement {
public static void main( String args [ ] ) {
int [ ] marks = {88 , 89 , 29 , 91 , 92};
for(int x : marks ) {
if( x <= 35 ) {
continue;
}
system.out.println(“Subjects passed are :”);
System.out.print( x );
}
}
}
Correct
Incorrect
Question 13 of 15
13. Question
When there will be a compile time error in the if statement?
Correct
Incorrect
Question 14 of 15
14. Question
class NestedIf {
public static void main ( String args [ ] )
{
int a = 8;
if(a<10) {
if(a<=8) {
if(a<8){
system.out.println(“ Number is less than 8 “);
}
system.out.println(“Number is less than or equal to 8”);
}
system.out.println(“Number is greater than 10);
}
}
}
Correct
Incorrect
Question 15 of 15
15. Question
Which of the following statements is more efficient than executing a long if else ladder?
Correct
Incorrect
Summary:
This interactive quiz has put those skills to the test, covering a range of decision-making concepts. By taking this quiz, you’ve actively engaged with different problem-solving scenarios, reinforcing your knowledge and identifying areas for further exploration.
Remember, continuous practice and exploration are key to mastering any programming language. Keep exploring, keep practising, and make those decisions count in your Java code!
Did you like our efforts? If Yes, please give DataFlair 5 Stars on Google
DataFlair Team provides high-impact content on programming, Java, Python, C++, DSA, AI, ML, data Science, Android, Flutter, MERN, Web Development, and technology. We make complex concepts easy to grasp, helping learners of all levels succeed in their tech careers.