Java Code Example: simple if-else statement

The SimpleIfExample is a Java program that demonstrates the use of a simple if statement to check a Boolean condition.

In the program, there is a Boolean variable isSet that is initialized to false. The if statement checks whether isSet is not true (!isSet). If isSet is not true, the code block inside the if statement is executed, which sets isSet to true using the assignment operator (=).

After the if statement, the program outputs the value of isSet using the System.out.print method. If isSet was previously false, the output will be true, since the value was updated in the if statement.

public class SimpleIfExample {
    public static void main(String[] args) {
        boolean isSet = false;

        if (!isSet)
            isSet = true;


In summary, the program demonstrates how to use a simple if statement to conditionally execute code based on a Boolean condition, and how to update the value of a Boolean variable within the if statement.