Switch

What is Switch? that finds the exact match variable or keyword then it will executes the result

int day = 4;

switch (day) {

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;

}

Result: Thursday

its due to case 4 is match exact with the variables selected

Explanation code

int day = 4; -> its declare of the variable day with value 4

switch (day) -> The switch declares the variable

case 1 (example) -> is too tight at each variable

System.out.println("Thursday"); -> to print out the result

break; -> is to break the statement for each unmatch case