32 Switch case statement in Java

Syntax:

switch( expression )
{
      case value1 :  statements
                           break;
      default : statement;
}

Program to print day of week name using switch case


6IFelseIFladder.java

class SwitchCase{

public static void main( String args[] ){
int ch=Integer.parseInt(args[0]);

System.out.println("\n\n Entered Choice: "+ch);

System.out.print("\n\n Day: ");
switch(ch){

case 1 : System.out.println("Monday");
break;
case 2 : System.out.println("Tuesday");
break;
case 3 : System.out.println("Wednesday");
break;
case 4 : System.out.println("Thursday");
break;
case 5 : System.out.println("Friday");
break;
case 6 : System.out.println("Saturday");
break;
case 7 : System.out.println("Sunday");
break;
default : System.out.println("Wrong Input");
}
}
}


Output: 

Previous
Next Post »