5.1 Conditional Statements (if, if-else, switch):

Conditional statements allow your program to make decisions and execute different blocks of code based on certain conditions.

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

        if (age >= 18) {
                System.out.println("You are eligible to vote.");
        }

    }
}

Output: "You are eligible to vote.”

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

    if (temperature > 30) {
      System.out.println("It's a hot day.");
    } else {
      System.out.println("It's a moderate day.");
    }
  }
}

Output: "It's a moderate day.”

class SwitchExample {
  public static void main(String[] args) {
    String dayOfWeek = "Tuesday";

    switch (dayOfWeek) {
      case "Monday":
        System.out.println("It's the beginning of the week.");
        break;
      case "Tuesday":
        System.out.println("It's a regular workday.");
        break;
      case "Saturday":
      case "Sunday":
        System.out.println("It's the weekend!");
        break;
      default:
        System.out.println("Invalid day.");
    }
  }
}

Output: "It's a regular workday.”

5.2 Looping Statements (while, do-while, for):

Looping statements allow you to repeat a block of code multiple times based on a condition.

class WhileExample{
    public static void main(String[] args) {
        int count = 1;
        while (count <= 5) {
            System.out.println("Count: " + count);
            count++;
        }
    }
}

Output:

Count: 1
Count: 2
Count: 3
Count: 4
Count: 5