Overview: 3.1.0

  • Boolean variables and expressions can only have true and false values

Testing Equality: 3.1.1

  • == and != can be used to compare values
    • Return true or false boolean values
    • Single equals is assignment (changes a variable’s value); double equals checks for equality! (doesn’t change value)
    • Also used to test if two reference values refer to the same object

Relational Operators: 3.1.2

  • Relational operators compare numeric values/expressions
    • < less than
    • > greater than
    • <= less than or equal to
    • >= greater than or equal to
    • == equal to
    • != not equal to

Testing with mod: 3.1.3

// Test if a number is positive
(number > 0)
//Test if a number is negative
(number < 0)
//Test if a number is even by seeing if the remainder is 0 when divided by 2
(number % 2 == 0)
//Test if a number is odd by seeing if there is a remainder when divided by 2
(number % 2 > 0)
//Test if a number is a multiple of x (or divisible by x with no remainder)
(number % x == 0)

Summary: 3.1.5

  • Primitive values and reference values can be compared using relational operators
  • Arithmetic expressions and values can be compared using relational operators
  • An expression using relational operators evaluates to a boolean value