NEW
Font size
Worksheets"switch" Java Statement - 1
Total questions: 17
Worksheet time: 34mins
A SWITCH case statement in Java is a ___ control statement.
Iteration
Looping
Selection
Jump
Which is the alternative to SWITCH in Java language?
break, continue
for, while
if-else
goto, exit
What are the keywords used to implement a SWITCH case in Java language?
switch, case
default
break
All of above
A SWITCH statement accepts ___ type of data as input.
byte
short
int
All of above
Choose the correct syntax of SWITCH statement in Java below.
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default: //statements;
};
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default: //statements;
}
switch(input)
{
case constant1: //statements; break;
case constant2: //statements; break;
default case: //statements;
};
What is the output of Java program with SWITCH below?
int a=10;
switch(a)
{
case 10: System.out.println("TEN");
}
No Output
TEN
Compiler error as there is no break
None
What is the output of the Java program below?
int b=20;
switch(b)
{
default: System.out.println("LION");
}
No Output
LION
Compiler error as there are no CASE statements.
None
What is the output of Java program with SWITCH?
int num=20;
switch(num)
{
case 10: System.out.println("TEN"); break;
case 20: System.out.println("TWENTY"); break;
case 30: System.out.println("THIRTY");
}
TEN
TWENTY
THIRTY
TEN TWENTY
What is the output of Java program below?
int num=40;
switch(num)
{
case 5: System.out.println("FIVE"); break;
case 35+5: System.out.println("FORTY"); break;
case 20+30: System.out.println("FIFTY");
}
FIVE
FORTY
FIFTY
Error
What is the output of the below Java program?
int persons = 45;
int random = 45;
switch(random)
{
case persons: System.out.print("CRICKET ");
default: System.out.println("RUGBY");
}
CRICKET
CRICKET RUGBY
RUGBY
Compiler error
What is the output of the below Java program?
final int persons = 45;
int random = 45;
switch(random)
{
case persons: System.out.print("CRICKET ");
default: System.out.println("RUGBY");
}
CRICKET
CRICKET RUGBY
RUGBY
Compiler error
What is the output of the below Java program?
switch(15)
{
case 5*2: System.out.println("TEN");break;
case 5*4-5:System.out.println("FIFTEEN");break;
case 60/4+5: System.out.println("TWENTY");
}
TEN
FIFTEEN
TWENTY
Error
A SWITCH fall through occurs in Java only in the absence of ___.
Keyword "case"
Keyword "break"
Keyword "default"
None of these
Does the following Java code-snippet compile?
switch(45)
{
case 10: ;
}
Yes
No
What is the output of the below Java program with a SWITCH statement?
int points=6;
switch(points)
{
case 6: ;
case 7: System.out.print("PASS");
case 8: ;
case 9: System.out.print(" Excellent");
case 10: System.out.print(" Outstanding"); break;
default: System.out.print("FAIL");
}
PASS Excellent Outstanding
Excellent
Outstanding
FAIL
What is the output of the below Java program?
int hours = 10;
switch(hours)
{
case 10: System.out.println("TEN");break;
case 10: System.out.println("TEN AGAIN"); break;
default: System.out.println("TEN AS USUAL");
}
TEN
TEN AGAIN
TEN AS USUAL
Compile
What will be the value of "y" after execution of this snippet-
0
4
1
2
