if-else Statement in Java


The if-else statement is used to perform a test and execute a block of code based on the result.

Source Code

int number = 10;
if (number > 0) {
    System.out.println("The number is positive.");
} else {
    System.out.println("The number is not positive.");
}

Use if-else statements to control the flow of your program based on conditions.

Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments