Switch Statements
Above are some java code samples using switch statements.
Instead of writing many if/else statements, you can use a switch statement. The switch statement will allow a certain block of code to be executed if there is a match with the case. If there is no match to a case the default case will be executed if the default case has been incuded. After executing the code within a case the break keyword is used to stop the execution of more code and case testing.
Quiz
Add space in condition ex. (x > 0) not (x>0).
-
What will the output be for this program if caseChoice equals 2?
-
What will the output be for this program if caseChoice equals 10?
-
What will the output be for this program if caseChoice equals 4.