Java Switch Case Statement

By Kunal Kapoor
19-04-2018
618

Switch case is a multiple branched conditions. It can execute based on the input case value.

Unlike the if condition, switch can have multiple cases.

Switch condition works on a specific type of input, like a integer based conditions,char based, etc


break statement 

Purpose of break is to finish the switch condition once the condition is executed. If break is not applied, the compiler will execute all the conditions after your set condition

eg:



myClass.java:

package control_statements_2;

public class myClass {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		
		int condition=2;
		
		switch(condition) {
		case 1:
			System.out.println("Execution case 1");
			break;
			
		case 2:
			System.out.println("Execution case 1");
			break;
			
		case 3:
			System.out.println("Execution case 1");
			break;
			
		}

	}

}
output:
Execution case 1



Related Tutorials