Chapter Table of Contents
Ch. 6 ConditionalsSection Table of Contents
So a while back, we talked about booleans. Now we will combine that skill with conditionals to really gain control and manipulate our Java programs.
Recall that booleans can only have 2 states:
true
or false
. This is very handy when we need to pick and choose which code to run. For instance, what if I wanted to make a program that printed out whether I could vote depending on what my age is?I could have a
boolean
called canVote
, which stores whether I can vote or not. To be more specific, I could have a condition like: canVote
is true
when age
is greater than or equal to 18. How do we represent expressions with inequalities? We can use relational operators.Next Section
6.2 Relational OperatorsCopyright © 2021 Code 4 Tomorrow. All rights reserved.
The code in this course is licensed under the MIT License.
If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.