3.2 If Statements and Control Flow

Screenshot 2024-09-16 at 8 07 34 AM Screenshot 2024-09-16 at 8 07 41 AM

Popcorn Hack

Create test cases that do not satisy the condition above. You can copy/paste the code into the new code cell.

public static void main(String[] args) {
    int myAge = 16;
    System.out.println("Current age: " + myAge);

    int yourAge = 5; // THIS TESTCASE WILL FAIL
    int skibidiAge = 1; // THIS TESTCASE WILL ALSO FAIL
    
    if (myAge >= 16) {
        System.out.println("I can start learning to drive!");
    }
    
    if (yourAge >= 16) {
        System.out.println("You can start learning to drive!");
    }

    if (skibidiAge >= 16) {
        System.out.println("Those at skibidi age can start learning to drive!");
    }

    System.out.println("On your next birthday, you will be " + (myAge + 1) + " years old!");
}

main(null);
Current age: 16
I can start learning to drive!
On your next birthday, you will be 17 years old!

If statements can be used to create chatbots –> Magpie Lab Screenshot 2024-09-25 at 2 40 43 AM

Screenshot 2024-09-25 at 2 40 54 AM

  • the user’s input affects the flow of the program