3 - Boolean Statements
3 - Boolean Statements
Statements
AP Computer Science A - Summer 2024
Mr. Taylor
Relational Operators
Relational operators relate things to one another
● Many times in code, it is useful to compare two numbers to see if
they’re equal, or if one is greater than the other, etc.
○ Relational operators allow us to do just that
List of relational operators
● > - Greater than
● < - Less than
● >= - Greater than or equal to
● <= - Less than or equal to
● == - Equal to
○ IMPORTANT: Single equals is assignment, double equals is comparing equality
● != - Not equal to
Relational Operators Examples
● int a = 8;
○ a == 10; // false
○ a < 10; // true
○ a >= 10; // false
○ a != 10; // true
● double b = 5.0;
○ b == 10.0; // false
○ b < a; // false
○ b >= a; // true
○ b != 5.000000001; // true
Checking doubles
● Sometimes we want to check if two doubles are close to each other,
but not necessarily exactly equal
○ The problem is that 10.0000001 == 10.0 is false