Guide to Object-oriented Programming With Java (Buffalo State University Version)
Chapter 8: Java Conditionals
Java conditionals provide a way to execute a statements or statements based on whether some condtion is met or not met.
Java if/else Conditional
The if statement allows you to test whether some condition is true or false. If the result of the test is true then the statement(s) between the first { and } are executed. If the result is false the then statement(s) between the else { and } are executed. For example:
The if/else if Conditional.
You can also useif to test whether some other condition if the result of the first if test is false. For example:
Java switch Conditional
The switch statement allows you to test whether some condition is met or not met. If the parameter that is passed to the switch statement is equal to any of the case statements then the statement(s) between that case: statement and break statement are executed. If the parameter does not match any of the case statements then the tatements after the default: statement(s) are executed. For example