Using if-else Statements in Java


if-else statements control the flow of your program by executing different code blocks based on conditions.

Source Code

public class IfElseExample {
    public static void main(String[] args) {
        int number = 10;
        if (number > 0) {
            System.out.println("Number is positive.");
        } else {
            System.out.println("Number is not positive.");
        }
    }
}
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments