![]() |
3.1: Boolean Expressions | 3.2: If Control Flow | 3.3: If Else | 3.4: Else If | 3.5: Compound Booleans | 3.6: Equivalent Booleans | 3.7: Comparing Objects | 3.8: Homework |
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!");
}
If statements can be used to create chatbots
–> Magpie Lab
- the user’s input affects the flow of the program
int myAge = -2;
System.out.println("Current age: " + myAge);
if (myAge >= 15) {
System.out.println("You can start learning to drive!");
}
System.out.println("On your next birthday, you will be " + (myAge + 1) + " years old!");
Current age: -2
On your next birthday, you will be -1 years old!
Comments
You are seeing this because your Disqus shortname is not properly set. To configure Disqus, you should edit your
_config.yml
to include either adisqus.shortname
variable.If you do not wish to use Disqus, override the
comments.html
partial for this theme.