Java Conditional Statements - The Coding Shala
Home >> Learn Java >> Java Conditional Statement
Java's Conditional Statements
Java Supports two conditional or selection statements: if and switch. These statements are used to control the flow to the program based on the condition that we have put.
Java If else Statement
The basic statement of Java's If the statement is as follows:
The condition is an expression returns a boolean value. The else part is optional.
Note: we can also use nested if statements. (if inside if statement)
The following Java program explains the if statement:
Java switch Statement
The basic syntax of Java's switch statement is as follows:
Here, expression and value specified in the case statement must be type compatible and can be a byte, short, int, or char. The default statement is executed when none of the case value matched with the value of the expression. The default statement is optional. The break statement is used to terminate a statement sequence that means used to jump out of the switch.
Note: we can also use nested switch statements.
The following Java Program explains the switch statement:
Other Posts You May Like