3. WHAT’S AN EXPRESSION?
In Math...
“Phrase” that can contain numbers,
variables (x,y,z,etc.) and operators
(add,subtract,multiply, and divide).
Example:
• a + 1
• a – b
• 3x
• x - a / b
4. IN COMPUTER SCIENCE AN EXPRESSION IS…
The same as it is in math!
Except…with a few added operators
5. OPERATORS
Subtraction -
Addition +
Multiplication *
Division /
Modulo (mod) %
Less than <
Less Than or Equal to <=
Greater than >
Greater than or Equal to >=
AND &&
OR ||
Not Equal !=
Equal Equal ==
Not !
6. PRECEDENCE
• Similar to PEMDAS in math
• Parentheses
• Exponents
• Multiplication/Division (left to right)
• Addition/Subtraction (left to right)
• Parentheses
• Modulo (Mod)
• Multiplication/Division (left to right)
• Addition/Subtraction (left to right)
• Boolean Logic such as
|| OR
&& AND
< Less than
<= Less than or equal to
> Greater than
>= Greater than or equal to
!= Not Equal
= Equal
! Not
The Computer Science Version
7. A FEW EXAMPLES
Expression Value
1)3 + 3 + “six” + (3 + 3) * 3 % 3
2)(11 != 7 + 4 || 3 * 2 <= 39 % 10) == false
*Answer Key with Steps will be posted online under “Lecture Materials”
8. GROUP WORK
• Get to know each other
• Solve these problems…
• 15-20 min
• Share out
5 * 6 - (4 + 3) * 2 - 2 * 3
208 / 20 / 4 + 12 / 10.0 + 0.4 * 24.0
8 - 2 + "8 - 2" + 8 * 2 + 8 "68 - 2168"
4 * 5 % 6 + 297 % 10 + 4 % 813
13 / 2 * 3.0 + 5.5 * 3 / 226.25