Unit 1 · Using Objects and Methods
Primitive Expressions
Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.
What primitive expressions covers
Primitive expressions are where every AP CSA program starts. Java evaluates arithmetic using the types of the operands, not the type of the variable you are assigning into, so int / int stays an int and double arithmetic keeps its decimal part. Precedence follows the usual order: multiplication, division, and mod before addition and subtraction, with parentheses overriding everything. Compound assignment operators such as += and *= apply the operation and reassign in one step.
Where students lose points
The most common error is assuming the assignment target changes the arithmetic. In double average = 7 / 2; the division happens first in int arithmetic, so average holds 3.0, not 3.5. Students also lose points on compound assignment with mixed types, and on chained operations where they add left to right instead of respecting precedence.
How it shows up on the AP exam
This is Unit 1 material and it appears everywhere, because almost every code-tracing question contains an expression you must evaluate correctly before the rest of the trace can be right. Getting expressions wrong compounds through an entire FRQ.
For practice use only.
Primitive Expressions MCQ Practice
Practice AP CSA primitive expressions: int and double arithmetic, operator precedence, compound assignment, and the integer overflow traps that appear on the exam.
Answered 0 of 15
Choose one answer.
Which option matches the complete output produced by this segment?
public class PrimitiveExpressionsContext
{
public static void runExample()
{
int total = 47;
int box = 6;
System.out.print(total / box + " " + total % box);
}
public static void main(String[] args)
{
runExample();
}
}