You are here: Home / Topics / Simple Switch case example in Java

Simple Switch case example in Java

Filed under: Java on 2023-08-12 20:50:25

// Simple switch case example

class SwitchDemo 
{
public static void main( String args[ ] )
{
 int  a = 2;
 
 switch (a) 
 {
  case 1 :
   System.out.println("One.");
   break;
  case 2 :
   System.out.println("Two.");
   break;
  case 3 :
   System.out.println("Three.");
   break;
  default:
   System.out.println("Invalid value.");
 }
}
}


Output:

Two

About Author:
J
Java     View Profile
Hi, I am using MCQ Buddy. I love to share content on this website.