‫The third type of conditional statements is the switch statement.
‫The switch statement is used when you have multiple cases and need to perform different actions based
‫on the value of a variable.
‫For example, if I am checking here for the day of week and day of week is equal to three.
‫Switch is used to to check for the exact value of the variable.
‫I'll make a here the switch starting with the switch keyword.
‫I'm going to check the day of week variable.
‫If it is equal to one then system dot out dot println.
‫It's Sunday and don't miss to use the break the switch is checking the day of week.
‫If it is equal to one, it will print Sunday.
‫If it is equal to here case two then it will print.
‫It is Monday.
‫If it is.
‫Case three, then it will be.
‫Tuesday.
‫Okay.
‫And here I can end with the default.
‫Please pay attention with me and you'll understand everything here on.
‫No.
‫In this example, the switch statement checks the value of the variable day of week.
‫If it is equal to one, it will print Sunday.
‫If it is equal to two, it will print Monday.
‫If it is equal to three, it will print Tuesday, and in this case it will print Tuesday because the
‫day of week is equal to three, and the case three, which is equal to three, will be executed.
‫So this block of code will be executed if the value doesn't match any of the cases.
‫If we have day of week equal to eight, it will execute the default block setting and displaying the
‫message unknown.
‫So if there is no condition met or there is no case matched, it will print the default and execute
‫the default section.
‫Let me run, for example, the day equal to three.
‫Run the program and here we get Tuesday.
‫Let me change the day of week to eight.
‫It will print for us unknown because the default here, because the default block will be executed when
‫the value doesn't match any of the cases.
‫So this is how we use the conditional statements and how to use the switch in Java.