Unit3.2
3.2 If Statements and Control Flow
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);
if (myAge >= 16) {
System.out.println("You can start learning to drive!");
}
System.out.println("On your next birthday, you will be " + (myAge + 1) + " years old!");
}
int myAge = 15;
System.out.println("Current age: " + myAge);
if (myAge >= 16) {
System.out.println("You can start learning to drive!");
}
System.out.println("On your next birthday, you will be " + (myAge + 1) + " years old.");
myAge = 10;
System.out.println("\nCurrent age: " + myAge);
if (myAge >= 16) {
System.out.println("You can start learning to drive!");
}
System.out.println("On your next birthday, you will be " + (myAge + 1) + " years old.");
//created a test case for 10 and 15 lol
Current age: 15
On your next birthday, you will be 16 years old.
Current age: 10
On your next birthday, you will be 11 years old.
If statements can be used to create chatbots
–> Magpie Lab
- the user’s input affects the flow of the program