# Conditional Statements

### If/else statements

In Java, you can use if/else statements to control the flow of your program based on certain conditions. Here's an example:

```java
public class IfElseExample {
    public static void main(String[] args) {
        int age = 25;

        if (age >= 18) {
            System.out.println("You are an adult.");
        } else {
            System.out.println("You are a minor.");
        }
    }
}
```

In the above example, we use an if/else statement to check if the `age` variable is greater than or equal to 18. If it is, we display the message "You are an adult." If it's not, we display the message "You are a minor."

You can also use if statements without an else statement, like this:

```java
public class IfExample {
    public static void main(String[] args) {
        int age = 25;

        if (age >= 18) {
            System.out.println("You are an adult.");
        }

        System.out.println("Program complete.");
    }
}
```

In the above example, we use an if statement to check if the `age` variable is greater than or equal to 18. If it is, we display the message "You are an adult." Regardless of the result, we then display the message "Program complete."

### Switch statements

In Java, you can use switch statements to simplify complex if/else statements. Here's an example:

```java
public class SwitchExample {
    public static void main(String[] args) {
        int dayOfWeek = 2;

        switch (dayOfWeek) {
            case 1:
                System.out.println("Monday");
                break;
            case 2:
                System.out.println("Tuesday");
                break;
            case 3:
                System.out.println("Wednesday");
                break;
            case 4:
                System.out.println("Thursday");
                break;
            case 5:
                System.out.println("Friday");
                break;
            default:
                System.out.println("Weekend");
                break;
        }
    }
}
```

In the above example, we use a switch statement to check the value of the `dayOfWeek` variable. Depending on its value, we display the corresponding day of the week. The `default` case is used when none of the other cases match. The `break` statement is used to exit the switch statement and continue with the rest of the program.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://pankhaniyajay.gitbook.io/introduction-to-programming-fundamentals-java/conditional-statements.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
