Program to call the multiple methods in a Switch Case in java.

There are following way to call multiple methods in a Switch Case in java.

  • Create the Scanner object to take the input from user.
  • Here user enter value is compared with the value of switch case. if there is a match, then test method is executing.
  • The default keyword specifies some code to run if there is no case match.
import java.util.Scanner;
public class SwitchCase {
	public static void main(String[] args) {
		System.out.println("Enter a value :-");
		try  {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			switch (a) {
			case 10: test();
			break;
			default:
				System.out.println("invalid input");
			}
			sc.close();
		}catch(Exception ex) {
			ex.printStackTrace();
		}
	}
	public static void test() {
		System.out.println("calling from switch case");
	}
}

Output :-
Enter a value :-
10
calling from switch case