Using If-Else Statements in Java

In Java, the if-else structure is utilized for conditional decision-making. It begins with the if keyword followed by a condition enclosed in parentheses. If the state is true, the code within the if bracket gets executed. An optional else segment can be added for cases where the condition is false. The else if clause can be used to check a series of conditions. Conditions are evaluated from the top downwards, and upon encountering a true condition, its corresponding code block runs, bypassing the remaining states. In this Java If-Else Example, we've set up a variable and determined its value using the if-else framework. Click Execute to run the Java If-Else Example online and see the result.
Using If-Else Statements in Java Execute
public class IfElseDemo {
    public static void main(String[] args) {
        int number = 10;

        if (number > 10) {
            System.out.println("Number is greater than 10.");
        } else if (number < 10) {
            System.out.println("Number is less than 10.");
        } else {
            System.out.println("Number is equal to 10.");
Updated: Viewed: 48 times