Skip to main content
The new Teacher Workspace is here. Your first 3 assignments are free. Try it →
A colleague sent you $30 off Fiveable. Get the annual plan for $99 →

+ Operator in AP Computer Science A

In AP Computer Science A, the + operator performs arithmetic addition when both operands are numbers, and string concatenation when at least one operand is a String. Java evaluates + left to right, so the operand types at each step decide the result.

Verified for the 2027 AP Computer Science A exam•Last updated October 2026

What is + Operator?

The + operator is Java's one operator with two jobs. When both sides are numbers (int or double), it adds them. Per EK 1.3.C.2, int + int gives an int, and if at least one operand is a double, the result is a double. When at least one side is a String, + concatenates, which means it glues the two values together into one longer String. The non-String value gets converted to text first.

The tricky part is that Java reads a chain of + signs left to right, one pair at a time. So "Value: " + 5 + 7 becomes "Value: 5" first, then "Value: 57". The 5 and 7 never get added, because by the time Java reaches them, it's already working with a String. Flip the order and 5 + 7 + " apples" gives "12 apples", because the numbers meet first. Think of it this way: once a String enters the chain, everything after it gets glued, not added.

Why + Operator matters in AP® Computer Science A

The + operator lives in Topic 1.3 Expressions and Assignment Statements in Unit 1: Using Objects and Methods. It sits at the intersection of three learning objectives. 1.3.C covers developing arithmetic expressions and determining their results, which is where + as addition and the int/double typing rules come in. 1.3.B covers using string literals, which is where + as concatenation comes in. 1.3.A covers determining what System.out.print and System.out.println display, and those statements are where you'll see + most often on the exam. Because so many output-tracing questions build their printed text with +, getting this operator wrong can cost you points on questions that look like they're about something else entirely.

How + Operator connects across the course

Operator Precedence (Unit 1)

The + operator has lower precedence than *, /, and %, so 8 + 3 * 2 is 14, not 22. Inside a concatenation chain, precedence still applies. "Total: " + 3 * 2 prints Total: 6 because the multiplication happens before any gluing.

String Literals and Escape Sequences (Unit 1)

Concatenation is how you build output out of pieces like "Name: " and a variable. Escape sequences such as \n and \" ride along inside those literals. That means "Line1" + "\n" + "Line2" prints on two lines even though you only called println once.

Integer Division and int/double Typing (Unit 1)

The same typing rule that makes 7 / 2 equal 3 also governs addition. 3 + 4 is the int 7, but 3 + 4.0 is the double 7.0. That matters when the sum gets concatenated, because "" + 7.0 prints 7.0, not 7.

String Methods like length() (Unit 1)

Method calls return values that then join the + chain. In "Length: " + word1.length() + word2.length(), each length is an int, but the String came first. So the lengths get glued side by side (like 411) instead of summed (15).

Is + Operator on the AP® Computer Science A exam?

The + operator shows up mostly in multiple-choice "What is printed as a result of executing the following code segment?" questions. Your job is to trace the expression left to right and track whether each step is a number or a String. Typical setups include:

  • System.out.println("Value: " + 5 + 7); prints Value: 57, not Value: 12.
  • System.out.println(num + " " + word1 + " " + word2); with num = 42 prints 42 Code Java.
  • System.out.print(8 + 3 * 2); prints 14, which tests precedence with no Strings involved.
  • "Length: " + word1.length() + word2.length() glues the two lengths together instead of adding them.

The wrong answer choices are usually the "added it" version and the "glued it" version, so the exam is checking whether you know which one Java actually does. No released FRQ has used the term verbatim, but FRQ code regularly builds Strings with +. Writing "Total: " + (a + b) with parentheses is the clean way to force addition before concatenation.

+ Operator vs Arithmetic addition vs. string concatenation

They use the exact same symbol, so the operands decide which one happens. If both operands are numbers, + adds them. If either operand is a String, + concatenates. Because Java evaluates left to right, the same numbers can be added in one spot and glued in another. In 1 + 2 + "x" + 1 + 2, you get 3x12. Use parentheses when you want addition to happen inside a String expression.

Key things to remember about + Operator

  • The + operator adds when both operands are numbers and concatenates when at least one operand is a String.

  • Java evaluates a chain of + operators from left to right, so the type of the running result at each step decides whether the next + adds or concatenates.

  • Once a String appears earlier in the chain, every later + concatenates, which is why "Value: " + 5 + 7 prints Value: 57.

  • Multiplication, division, and remainder happen before +, so 8 + 3 * 2 evaluates to 14.

  • Adding two int values gives an int, but adding an int and a double gives a double, and that type shows up in the printed output.

  • Wrapping arithmetic in parentheses, like "Sum: " + (a + b), forces the addition to happen before the concatenation.

Frequently asked questions about + Operator

What does the + operator do in Java for AP CSA?

It does two different jobs. With two numeric operands it performs addition, following the rule that int + int gives an int and anything with a double gives a double. With at least one String operand it concatenates, joining the values into a single String.

Does "Value: " + 5 + 7 print Value: 12?

No, it prints Value: 57. Java goes left to right, so "Value: " + 5 becomes the String "Value: 5", and then + 7 glues on a 7. To get 12, write "Value: " + (5 + 7).

What is the difference between addition and concatenation in Java?

Addition combines two numbers mathematically, so 4 + 11 is 15. Concatenation joins text, so "4" + 11 is "411". Java uses the same + symbol for both and picks one based on whether a String is involved at that step.

Why does 42 + " " + "Code" print 42 Code but 5 + 7 + " apples" print 12 apples?

In both cases Java evaluates left to right. In the first, 42 meets a String right away, so it gets converted to text. In the second, 5 and 7 are both ints when they meet, so they're added to 12 before the String shows up.

Is the + operator on the AP Computer Science A exam?

Yes. It is part of Topic 1.3 in Unit 1 and supports learning objectives 1.3.A, 1.3.B, and 1.3.C. It appears constantly in "what is printed" multiple-choice questions and in FRQ code that builds output Strings.