wayground logo

Free Printable Worksheets

NEW

Font size

S
M
L
XL
Worksheets

"switch" Java Statement - 1

Total questions: 17

Worksheet time: 34mins

Name
Class
Date
1.

A SWITCH case statement in Java is a ___ control statement.

a)

Iteration

b)

Looping

c)

Selection

d)

Jump

2.

Which is the alternative to SWITCH in Java language?

a)

break, continue

b)

for, while

c)

if-else

d)

goto, exit

3.

What are the keywords used to implement a SWITCH case in Java language?

a)

switch, case

b)

default

c)

break

d)

All of above

4.

A SWITCH statement accepts ___ type of data as input.

a)

byte

b)

short

c)

int

d)

All of above

5.

Choose the correct syntax of SWITCH statement in Java below.

a)

switch(input)

{

case constant1: //statements; break;

case constant2: //statements; break;

default: //statements;

};

b)

switch(input)

{

case constant1: //statements; break;

case constant2: //statements; break;

default: //statements;

}

c)

switch(input)

{

case constant1: //statements; break;

case constant2: //statements; break;

default case: //statements;

};

6.

What is the output of Java program with SWITCH below?


int a=10;

switch(a)

{

case 10: System.out.println("TEN");

}

a)

No Output

b)

TEN

c)

Compiler error as there is no break

d)

None

7.

What is the output of the Java program below?


int b=20;

switch(b)

{

default: System.out.println("LION");

}

a)

No Output

b)

LION

c)

Compiler error as there are no CASE statements.

d)

None

8.

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");

}

a)

TEN

b)

TWENTY

c)

THIRTY

d)

TEN TWENTY

9.

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");

}

a)

FIVE

b)

FORTY

c)

FIFTY

d)

Error

10.

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");

}

a)

CRICKET

b)

CRICKET RUGBY

c)

RUGBY

d)

Compiler error

11.

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");

}

a)

CRICKET

b)

CRICKET RUGBY

c)

RUGBY

d)

Compiler error

12.

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");

}

a)

TEN

b)

FIFTEEN

c)

TWENTY

d)

Error

13.

A SWITCH fall through occurs in Java only in the absence of ___.

a)

Keyword "case"

b)

Keyword "break"

c)

Keyword "default"

d)

None of these

14.

Does the following Java code-snippet compile?


switch(45)

{

case 10: ;

}

a)

Yes

b)

No

15.

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");

}

a)

PASS Excellent Outstanding

b)

Excellent

c)

Outstanding

d)

FAIL

16.

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");

}

a)

TEN

b)

TEN AGAIN

c)

TEN AS USUAL

d)

Compile

17.

What will be the value of "y" after execution of this snippet-

a)

0

b)

4

c)

1

d)

2