πŸ“š

Β >Β 

πŸ’»Β 

Β >Β 

πŸ–₯

3.1 Boolean Expressions

1 min readβ€’december 21, 2022

Milo Chang

Milo Chang

Athena_Codes

Athena_Codes


AP Computer Science AΒ πŸ’»

130Β resources
See Units

Sometimes, we want to compare two numbers or see if two things are equal. To do this, we use boolean expressions, which represent logic and tell whether something is true or false. These are the two values that boolean primitive types can take!

Boolean Operators

There are several operators that can be used to create boolean expressions. Any statement containing these operators will result in a boolean. Here are the operators and what they do:
  • == equals to (two primitive types have the same value)
  • != checks for inequality (not equal)
  • < less than
  • <= less than or equal to
  • > greater than
  • >= greater than or equal to
We will restrict the equality and inequality operators to primitive types for now. We will discuss the equality of objects in 3.7! The four remaining operators only work for numerical types (integers and doubles), but they work exactly like you would expect (ie. 3 < 5 returns true while 3 >= 5 returns false).
You can use boolean statements in conjunction with other operators as well, such as in the following statement: (a%2) == 0
This statement is asking if the value represented by a is even or not. If it is even, then we return true. If it is not, we return false.

Browse Study Guides By Unit
βž•Unit 1 – Primitive Types
πŸ“±Unit 2 – Using Objects
πŸ–₯Unit 3 – Boolean Expressions & if Statements
πŸ•ΉUnit 4 – Iteration
βš™οΈUnit 5 – Writing Classes
⌚️Unit 6 – Array
πŸ’ΎUnit 7 – ArrayList
πŸ’»Unit 8 – 2D Array
πŸ–²Unit 9 – Inheritance
πŸ–±Unit 10 – Recursion

Fiveable
Fiveable
Home
Stay Connected

Β© 2024 Fiveable Inc. All rights reserved.


Β© 2024 Fiveable Inc. All rights reserved.