Java-Switch Statement

Switch Statement The switch statement is provides a better alternative than a large series of if-else-if statements. Here is its general form: The expression must be of type byte, short, int, or char; each of the values specified in the case statements must be of a type compatible with the expression. Each case value must … Read more…

Java-If-Else-If Ladder

If-Else-If Ladder The sequence of nested ifs is the if-else-if ladder. Here is the general form of the if-else-if statement: The if statements are executed from the top down. As soon as one of the conditions controlling the if is true, the statement associated with that if is executed, and the rest of the ladder is bypassed. … Read more…

Java-Nested If Statement

Nested If Statement A nested if is an if statement that is the target of another if else. Nested ifs are very common in programming. When you nest ifs, the main thing to remember is that an else statement always refers to the nearest if statement. Program Program Source class Javaapp { public static void main(String[] args) … Read more…

Java-If Else Statement

If Else Statement The ‘if else’ statement is an extension of the simple if statement. The general form of a ‘if else’ statement is : The ‘statement-block’ may be a single statement or a group of statements. If the test expression is true, the statement-block will be executed; If the test expression is false, the else-statement-block … Read more…