APrep Open the app

AP Computer Science Principles · Unit 3: Algorithms & Programming

3.3 Mathematical Expressions

Arithmetic Operators

Programs use arithmetic operators to perform calculations: addition (+), subtraction (-), multiplication (*), division (/), and mod (%). The mod operator returns the remainder of division — for example, 17 MOD 5 = 2. Mod is commonly used to check if a number is even/odd or to wrap values around a range.

Order of Operations

Expressions follow standard order of operations: parentheses first, then exponents, then multiplication/division/mod, then addition/subtraction, evaluated left to right. Using parentheses can force a different evaluation order and improves clarity. Misplaced or missing parentheses are a common source of logic errors in expressions.

Expressions with Variables

A mathematical expression combines variables, constants, and operators to produce a single value. When a variable appears in an expression, its current stored value is used in the calculation. The result of an expression can be stored back into a variable, updating its value based on the previous one (e.g., score = score + 10).

Key terms

Mod operator (%)
Returns the remainder after division; e.g., 17 MOD 5 = 2.
Order of operations
Parentheses, then exponents, then multiplication/division/mod, then addition/subtraction, left to right.
Mathematical expression
A combination of variables, constants, and operators that evaluates to a single value.
Why use mod to check even/odd?
num MOD 2 == 0 means even; MOD 2 == 1 means odd, since it checks the division remainder.
x = x + 5
Uses the current value of x, adds 5, and stores the result back into x, updating its value.

Try an AP-style question

In AP pseudocode, what is 17 MOD 5?

  1. 3.4
  2. 12
  3. 3
  4. 2
Show the answer

D. Remainder.

Practice 8 AP-style questions with instant explanations, flashcards and spaced review.

Study 3.3 free in APrep