Java - Switch case

Java - Switch case

9th Grade

5 Qs

quiz-placeholder

Similar activities

operators(part-2_26/07)

operators(part-2_26/07)

9th Grade

10 Qs

while loop

while loop

9th Grade

10 Qs

C++ Basics Quiz

C++ Basics Quiz

9th - 12th Grade

10 Qs

APCSA - Unit 3

APCSA - Unit 3

9th - 12th Grade

10 Qs

Ternary Operators

Ternary Operators

9th Grade

8 Qs

Using Simple string Methods

Using Simple string Methods

9th - 12th Grade

10 Qs

Java2

Java2

6th - 11th Grade

8 Qs

Loops

Loops

9th - 12th Grade

10 Qs

Java - Switch case

Java - Switch case

Assessment

Quiz

Computers

9th Grade

Easy

Created by

Vidya Byju

Used 2+ times

FREE Resource

5 questions

Show all answers

1.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a switch case statement, what happens if none of the cases match the value of the expression?

The program terminates.

The default case is executed (if provided).

An error is generated.

The program goes into an infinite loop.

2.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

In a switch case statement, what is the purpose of the "case" keyword?

To specify a condition

To define a variable

To start a loop

To identify a code block to execute

3.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

Which data type is commonly used as the expression inside a switch case statement?

int

float

boolean

string

4.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

public class Main {

public static void main(String[] args) {

int score = 85;

switch (score / 10) {

case 10:

case 9:

System.out.println("A");

break;

case 8:

System.out.println("B");

case 7:

System.out.println("C");

break;

default:

System.out.println("D or F");

}

}

}

error

A

B

B

C

5.

MULTIPLE CHOICE QUESTION

30 sec • 1 pt

public class Main {

public static void main(String[] args) {

int num = 90; // ASCII 90 is Z

switch ((char) (num - 21)) {

case 'A':

System.out.println("Found A");

break;

case 'E':

System.out.println("Found E");

case 'I':

System.out.println("Found I");

break;

case 'Z':

System.out.println("Found Z");

break;

default:

System.out.println("Found something else");

}

}

}

Found Z

Found E

Found I

Error

Found something else