wayground logo

Free Printable Worksheets

Font size

S
M
L
XL
Worksheets

Topic 4-2: Multiple if-else and switch-case

Total questions: 10

Worksheet time: 10mins

Name
Class
Date
1.

What value is assigned to fee by the multiple if-else statement when speed is 75?

a)

40.00

b)

60.00

c)

20.00

d)

error

2.

What value is assigned to fee by the multiple if-else statement when speed is 75?

a)

60.00

b)

20.00

c)

40.00

d)

error

3.

What is the output when the value of number is 20?

a)

A

b)

B

c)

C

d)

error

4.

What is the output when the value of number is 10?

a)

A

b)

B

c)

C

d)

error

5.

What is the output when the value of number is 50?

a)

A

b)

B

c)

C

d)

error

6.

boolean attendance = true;

Which of the following if statement includes a condition that evaluates to true? (can select more than 1)

a)

if(attendance) {...}

b)

if(attendance == "true") {...}

c)

if(attendance == true) {...}

d)

if(attendance != false) {...}

7.

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;

};

8.

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

9.

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

10.

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