Font size
S
M
L
XL
Worksheetsswitch statements + java
Total questions: 82
Worksheet time: 27mins
Name
Class
Date
1.
The following Java program uses a switch statement to print the current version of a programming language. Which programming language is the user input in the program?
a)
Java
b)
Python
c)
Rust
d)
JavaScript
2.
Which of the following statements is printed when the variable n is equal to 10?
a)
-10
b)
-98
c)
= -3
d)
non of the above
3.
What is the output of the code in the image?
a)
You are under 21
b)
You are eligible for marriage now
c)
You are over age
d)
Invalid age
4.
What is the output of the code in the image when the value of num is 2?
a)
Case1: Value is: 2
b)
Case2: Value is: 2
c)
Case3: Value is: 2
d)
Default: Value is: 2
5.
What is the output of the code in the image when the value of weekday is 3?
a)
Sunday
b)
Monday
c)
Tuesday
d)
Invalid weekday
6.
Which of the following statements is printed when the value of n is 10?
a)
-10
b)
-98
c)
= -3
d)
none of the above
7.
What is the output of the code in the image when the value of n is 11?
a)
-10
b)
-98
c)
= -3
d)
11
8.
What is the output of the code in the image when the value of day is "Saturday"?
a)
Attendance Required
b)
No Attendance. Its Holiday
c)
Invalid day
d)
none of the above
9.
What is the output of the code in the image when the value of day_name is "Friday"?
a)
1
b)
2
c)
3
d)
5
10.
What is the output of the code in the image when the value of user is 18?
a)
You are under 18
b)
You are eligible for marriage now
c)
You are over age
d)
Invalid age
11.
Which of the following is the output of the program if the user enters their age as 20?
a)
Your age is less than 21.
b)
Your age is 19.
c)
Your age is 20.
d)
Your age is greater than 28.
12.
Which of the following is the correct output of the statement if the variable expression has the value 10?
a)
Statement 1
b)
Statement 2
c)
Statement 1 and Statement 2
d)
None of the above
13.
The image shows a Java program that uses a switch statement to determine the user's batch number. If the user enters their batch number as "011106", what is the output of the program?
a)
Your batch number is 24.
b)
Your batch number is 20.
c)
Your batch number is 37.
d)
The program will not output anything.
14.
What is the purpose of the default code block?
a)
To execute if the value of the expression does not match any of the case statements.
b)
To execute if the value of the expression is equal to 0.
c)
To execute if the value of the expression is equal to 1.
d)
To execute if the value of the expression is equal to 2.
15.
What is the output of the program if the user enters the number 1?
a)
Monday
b)
Tuesday
c)
Wednesday
d)
Thursday
16.
What is the output of the program if the value of the variable expression is 5?
a)
The program will print "The value of the expression is 5."
b)
The program will print "The value of the expression is not 5."
c)
The program will print nothing.
d)
The program will crash.
17.
If the value of the variable roll is 3, what is the output of the program?
a)
I am Pankaj.
b)
I am Nikhil.
c)
I am John.
d)
No student foun
18.
If the value of the variable value is 4, what is the output of the program?
a)
5
b)
6
c)
Cannot determine
d)
4
19.
The image shows a Java program that uses a switch statement to determine the power usage of a system. If the system is an ACS, what is the power usage?
a)
140
b)
200
c)
110
d)
Cannot be determined
20.
If the value of the variable color is "red", what is the output of the program?
a)
The color is red.
b)
The color is green.
c)
The color is blue.
d)
Cannot be determine
21.
If the value of the variable version is "SE 11 (LTS)", what is the output of the program?
a)
Latest version
b)
Older version, still supported
c)
Cannot be determined
d)
Unsupported version
22.
If the value of the variable value is 2, what is the output of the program?
a)
Value is 2.
b)
Value is not 2.
c)
Nothing is printed.
d)
The program crashes.
23.
What is the purpose of the default code block?
a)
To execute if the value of the expression does not match any of the case statements.
b)
To execute if the value of the expression is equal to 0.
c)
To execute if the value of the expression is equal to 1.
d)
To execute if the value of the expression is equal to 2.
24.
What is the output of the program if the value of the expression is 2?
a)
The value of the expression is 2.
b)
The value of the expression is not 2.
c)
The program will crash.
d)
Nothing will be printe
25.
What is the output of the program if the value of the variable grade is A?
a)
Excellent
b)
Very good
c)
Good
d)
The value of the variable grade is not A.
26.
If the user enters the letter a, what is the output of the program?
a)
The letter a
b)
The letter b
c)
The letter c
d)
Nothing will be printed
27.
Which of the following is the correct output of the Java code in the image?
a)
Value matched - a, a vowel
b)
Value matched - e, a vowel
c)
Value matched - w, not a vowel
d)
Sorry none of your cases matched
28.
What is the output of the Java code in the image?
a)
Khanh
b)
Huong Dan Java
c)
Lap Trinh Java
d)
Hello
29.
What is the output of the Java program in the image?
a)
Number is 15
b)
Number is 25
c)
Number is 35
d)
Number not found
30.
What is the next step in the flowchart?
a)
The statement is executed.
b)
The statement is skipped.
c)
The program terminates.
d)
The control goes to the default case.
31.
Which of the following is not one of the important points?
a)
There can be one or 'N' number of cases in a switch statement.
b)
Values should be unique.
c)
Data type value should be same as data type of variable.
d)
Wrapper Class can be used as the value of cases.
32.
Which of the following is the correct code for the program?
a)
int i = 0; while (i <= 5) { System.out.println(i); i++; }
b)
int i = 5; while (i >= 0) { System.out.println(i); i--; }
c)
int i = 0; do { System.out.println(i); i++; } while (i <= 5);
d)
int i = 5; do { System.out.println(i); i--; } while (i >= 0);
33.
What is the value of the variable age when the program terminates?
a)
10
b)
15
c)
20
d)
25
34.
What is the purpose of the default case?
a)
To execute a statement when the value of the variable does not match any of the case statements.
b)
To execute a statement when the value of the variable is equal to 0.
c)
To execute a statement when the value of the variable is greater than or equal to 0.
d)
To terminate the switch statement.
35.
What is the output of the switch statement if the value of the variable ch is equal to c?
a)
The statement for case 0 is executed.
b)
The statement for case c is executed.
c)
The statement for case d is executed.
d)
The statement for default is execute
36.
What is the output of the program if the value of the variable day is 3?
a)
Sunday
b)
Monday
c)
Tuesday
d)
Wednesday
37.
What is the purpose of the break statement?
a)
To terminate the switch statement.
b)
To skip to the next case statement.
c)
To execute the statement for the default case.
d)
To execute the statement for the case statement that matches the value of the variable.
38.
What is the output of the switch statement if the value of the variable a is equal to 10?
a)
The statement for case 10 is executed.
b)
The statement for case 20 is executed.
c)
The statement for default is executed.
d)
The switch statement is terminate
39.
What is the purpose of the default case?
a)
To execute a statement when the value of the variable does not match any of the case statements.
b)
To execute a statement when the value of the variable is equal to 0.
c)
To execute a statement when the value of the variable is greater than or equal to 0.
d)
To terminate the switch statement.
40.
Which of the following statements is true about the value of i in the Java program?
a)
The value of i is always greater than 2.
b)
The value of i is always less than 5.
c)
The value of i is greater than 2 and less than 5 only on the last two lines of the output.
d)
The value of i is greater than 2 and less than 5 on the first two lines of the output.
41.
What is the purpose of the break statement in the switch statement?
a)
The break statement is used to exit the switch statement when a matching case is found.
b)
The break statement is used to skip the rest of the cases in the switch statement.
c)
The break statement is used to go back to the beginning of the switch statement.
d)
The break statement is used to execute the next case in the switch statement.
42.
The switch statement has 6 cases. How many branches are covered by the switch statement?
a)
6 branches
b)
5 branches
c)
4 branches
d)
3 branches
43.
The switch statement has 3 cases. What is the value of the variable i after the switch statement is executed?
a)
0
b)
1
c)
2
d)
3
44.
What is the output of the switch statement if the constant expression evaluates to 1?
a)
Code block 1
b)
Code block 2
c)
Code block 3
d)
Default code
45.
Given the Java code fragment in the image, what is the output of the code if the value of ch is A?
a)
Good Luck
b)
To Your Exam
c)
Have Fun
d)
All the best
46.
What is the output of the code if the value of day is changed to "Tuesday"?
a)
Good morning!
b)
Have a nice day!
c)
See you tomorrow!
d)
Happy Tuesday!
47.
What is the highest version of Java that can be compiled with this setting?
a)
Java 8
b)
Java 9
c)
Java 10
d)
Java 11
48.
What is the power usage for an ACS system?
a)
100
b)
200
c)
110
d)
310
49.
What is the output of the code if the value of s is "T"?
a)
All 22 branches covered.
b)
2
c)
3
d)
6
50.
What is the output of the code if the value of x is 10?
a)
10
b)
20
c)
30
d)
40
51.
The coding window shows a Java code fragment. What is the output of the code if the value of Number is 25?
a)
Number is 15
b)
Number is 25
c)
Number is 35
d)
Number not found
52.
What is the output of the code if the value of variable/expression is 10?
a)
Code block 1
b)
Code block 2
c)
Code block 3
d)
Default code
53.
What is the output of the code if the value of month is 2?
a)
It has 28 days
b)
It has 30 days
c)
It has 31 days
d)
Please enter valid input
54.
What is the output of the code if the value of day is Thursday?
a)
It is Thursday.
b)
It is not Thursday.
c)
Invalid input.
d)
Please enter a valid day.
55.
The code has three cases. What is the output of the code if the value of randInt is 8?
a)
You look so much better than usual.
b)
You're quite competent for someone with so little experience.
c)
Your work is up to its usual standards.
d)
Oops--something is wrong!
56.
What is the output of the code if the value of value is 200?
a)
200
b)
100
c)
-1
57.
The flowchart shows the steps involved in a ________.
a)
Java switch statement
b)
C switch statement
c)
JavaScript switch statement
d)
Python switch statement
58.
Which of the following is the correct output of the code snippet?
a)
weekday
b)
weekend
c)
Monday
d)
Tuesday
59.
Which of the following is the correct output of the code snippet?
a)
if-else statement
b)
switch statement
c)
for loop
d)
do-while loop
60.
Which of the following is the correct output of the code snippet?
a)
weekday
b)
weekend
c)
Monday
d)
Tuesday
61.
Which of the following is the correct output of the code snippet?
a)
S
b)
O
c)
D
d)
None
62.
Which of the following is the correct output of the code snippet?
a)
i is less than 5
b)
i is less than 10
c)
i is 10 or more
d)
i is not less than 15
63.
The image shows a Java code snippet that uses a switch statement to determine the logical connector. Which of the following is the correct output of the code snippet?
a)
and
b)
or
c)
not
d)
invalid connector
64.
The image shows a JavaScript code snippet that uses a switch statement to determine the price of a food item. Which of the following is the correct output of the code snippet?
a)
$5
b)
$4
c)
$3
d)
$2
65.
Which of the following is the correct syntax for the case statement?
a)
case value: statement-list
b)
case value: statement-list break;
c)
case value: statement-list break else statement-list;
d)
case value: statement-list else statement-list;
66.
Which of the following is the correct output of the code snippet?
a)
The number is positive.
b)
The number is negative.
c)
The number is zero.
d)
The operation is not supporte
67.
Which of the following is the correct output of the code snippet?
a)
404 Not Found
b)
500 Internal Server Error
c)
503 Service Unavailable
d)
Invalid error code
68.
Which of the following is the correct syntax for the default case?
a)
default: statement-list
b)
default: statement-list break;
c)
default: statement-list else statement-list;
d)
default: statement-list else break;
69.
Which of the following is the correct syntax for the default case?
a)
default: statement-list
b)
default: statement-list break
c)
default: statement-list else: statement-list
d)
default: statement-list else: break
70.
The image shows a Java code snippet that uses a switch statement to determine the addressing mode. Which of the following is the correct output of the code snippet?
a)
ADDR_1
b)
ADDR_A
c)
ADDR_Z
d)
ADDR_ABS
71.
Which of the following is the correct output of the code snippet when the value of the i variable is 2?
a)
Hello
b)
World
c)
Invalid input
d)
None of the above
72.
Which of the following is the correct output of the code snippet when the value of the size variable is 5?
a)
Small
b)
Medium
c)
Large
d)
Extra large
73.
Which of the following is the correct output of the code snippet when the user enters the number 5?
a)
1
b)
2
c)
3
d)
4
74.
Which of the following is the correct output of the code snippet when the value of the age variable is 1?
a)
Entry is free!
b)
Entry is $5.
c)
Invalid input.
d)
None of the above.
75.
Which of the following is the correct output of the code snippet when the value of the day variable is 2?
a)
Monday
b)
Tuesday
c)
Wednesday
d)
Thursday
76.
Which of the following is the correct output of the code snippet when the value of the errorCode variable is 404?
a)
Something went wrong!
b)
Invalid error code.
c)
404 Not Found.
d)
500 Internal Server Error.
77.
Which of the following is the correct output of the code snippet when the value of the month variable is 2?
a)
February has 28 days.
b)
February has 29 days in a leap year.
c)
February has 30 days.
d)
Invalid month.
78.
Which of the following options should be added to the switch statement to print "Invalid enum value" when the value of the myEnum variable is not FOO, BAR, or BAZ?
a)
case INVALID: System.out.println("Invalid enum value"); break;
b)
default: System.out.println("Invalid enum value"); break;
c)
case INVALID: break;
d)
default: break;
79.
The screenshot shows a Java program that reads the age of a person. What is the output of the program if the user enters the age 20?
a)
Your age is 18
b)
Your age is 19
c)
Your age is 20
d)
matching records
80.
What is the output of the program if the value of a is B?
a)
Number 10 is found
b)
Character A is found
c)
No match found
d)
Matching records
81.
What is the output of the program if the user enters the numbers 1 and 3?
a)
4
b)
5
c)
6
d)
7
82.
What is the output of the program if the value of the variable a is equal to 2?
a)
Statement 1
b)
Statement 2
c)
Statement 3
d)
Statement 4
Reset
