Computer Applications

Consider the following code snippet:


int val = 2;
switch (val)
{
case 1: System.out.println("Case 1");
break;
case 2: System.out.println("Case 2");
break;
default: System.out.println("No match found");
break;
}

Which of the following statements is correct?

  1. case 1 will be executed.
  2. case 2 will be executed.
  3. default will be executed.
  4. both case 1 and 2 will be executed.

Java Conditional Stmts

10 Likes

Answer

case 2 will be executed.

Answered By

3 Likes


Related Questions