Arithmetic expression in AP Computer Science A

In AP Computer Science A, an arithmetic expression is code made of numeric values, variables, and the operators +, -, *, /, and % that evaluates to a single numeric result; two int operands produce an int, while at least one double operand produces a double (EK 1.3.C.2).

Verified for the 2027 AP Computer Science A examLast updated June 2026

What is arithmetic expression?

An arithmetic expression is any piece of Java code that combines numeric values, variables, and arithmetic operators to produce one numeric answer. Per EK 1.3.C.1 and 1.3.C.2, the five operators on the AP exam are addition +, subtraction -, multiplication *, division /, and remainder %. Something like x * 2 + 1 or total / count is an arithmetic expression.

The part the exam actually tests is the type of the result. The rule is simple but unforgiving. If both operands are int, the result is an int. If at least one operand is a double, the result is a double. That one rule explains why 5 / 2 gives 2 (integer division throws away the decimal portion, per EK 1.3.C.3) while 5.0 / 2 gives 2.5. One single .0 changes the entire answer.

Why arithmetic expression matters in AP® Computer Science A

Arithmetic expressions live in Topic 1.3 (Expressions and Assignment Statements) under learning objective 1.3.C, which asks you to develop code for arithmetic expressions and determine their results. They extend directly into Topic 1.5, where LO 1.5.A adds casting with (int) and (double), LO 1.5.B covers what happens when an int expression overflows past Integer.MAX_VALUE, and LO 1.5.C covers round-off errors with doubles. This is foundation-level material. Every loop counter, every average calculation, and every method you write for the rest of the course (and on FRQs) is built out of arithmetic expressions, so the int/double evaluation rules follow you through all four units.

How arithmetic expression connects across the course

Integer division (Unit 1)

Integer division is the single most-tested consequence of the arithmetic expression type rules. When both operands are ints, / keeps only the whole-number part of the quotient, so 7 / 2 is 3, not 3.5. If a multiple-choice answer looks 'off by the decimal,' integer division is usually the trap.

Cast operator (Unit 1)

Casting is how you override the default type rules inside an arithmetic expression. Writing (double) x / y converts x to a double before dividing, which forces real division. Placement matters, since (double)(x / y) divides as ints first and casts the already-truncated answer.

Remainder operator (Unit 1)

The % operator is one of the five arithmetic operators and returns what's left over after division. It powers classic AP patterns like checking evenness with x % 2 == 0 and pulling digits off a number, so treat it as a first-class citizen, not an afterthought.

Round-off error (Unit 1)

Arithmetic expressions with doubles can produce results too precise for memory to hold, causing round-off errors (EK 1.5.C.1). The CED's advice is blunt. When exactness matters, use int values. Int expressions have their own failure mode, integer overflow, when results exceed Integer.MAX_VALUE.

Is arithmetic expression on the AP® Computer Science A exam?

Arithmetic expressions show up constantly in 'what is printed?' multiple-choice questions, and the questions are engineered around the int/double rules. A typical stem mixes arithmetic with System.out.print: for example, evaluating vals[0] + x / y where x = 5 and y = 2. Since x / y is int division, it gives 2, and the result is 7.0, while vals[1] + (double) x / y gives 9.5 because the cast forces real division. Another classic trap mixes + with strings, where System.out.print(x + y + " ") adds first (printing 7 ) because evaluation runs left to right. On FRQs, you won't be asked to define the term, but nearly every method you write uses arithmetic expressions, and graders deduct points for integer division mistakes in averages and percentage calculations.

Arithmetic expression vs String concatenation with +

The + symbol does two different jobs in Java. Between two numeric values it's arithmetic addition, but if either operand is a String, it becomes concatenation. So 5 + 2 + " " prints 7 (addition happens first, left to right), while " " + 5 + 2 prints 52 because once a String enters the expression, everything after it gets glued on as text. Exam questions love putting the String in different positions to test exactly this.

Key things to remember about arithmetic expression

  • An arithmetic expression combines numeric values, variables, and the operators +, -, *, /, and % to produce a single int or double result.

  • If both operands are ints, the result is an int; if at least one operand is a double, the result is a double.

  • Dividing two int values keeps only the integer portion of the quotient, so 7 / 2 evaluates to 3, not 3.5.

  • Casting with (double) before division forces real division, but only if the cast happens before the divide, not after.

  • An int expression that goes past Integer.MAX_VALUE causes integer overflow, and an overly precise double result causes a round-off error.

  • When + touches a String anywhere in the expression, evaluation switches from addition to concatenation from that point onward.

Frequently asked questions about arithmetic expression

What is an arithmetic expression in AP Computer Science A?

It's code built from numeric values, variables, and the operators +, -, *, /, and % that evaluates to one numeric result of type int or double. It's covered in Topic 1.3 under learning objective 1.3.C.

Does 5 / 2 equal 2.5 in Java?

No. Both 5 and 2 are int values, so Java performs integer division and keeps only the whole-number part, giving 2. You'd need 5.0 / 2, 5 / 2.0, or a cast like (double) 5 / 2 to get 2.5.

How is an arithmetic expression different from string concatenation?

Both can use the + symbol, but arithmetic addition only happens when both operands are numeric. The moment a String appears, + switches to concatenation, so 5 + 2 + "!" prints 7! while "!" + 5 + 2 prints !52.

What happens if an arithmetic expression is too big for an int?

Integer overflow occurs (EK 1.5.B.3). Java ints are stored in 4 bytes, so any result outside the range from Integer.MIN_VALUE to Integer.MAX_VALUE wraps to an in-range value that is not mathematically correct.

Is the remainder operator % an arithmetic operator on the AP exam?

Yes. EK 1.3.C.2 lists exactly five arithmetic operators: +, -, *, /, and %. The remainder operator follows the same type rules as the others and shows up often in even/odd checks and digit extraction.