AP CSA Unit-Level MCQ

String Concatenation

Practice mode with 15 Java-focused questions, immediate answer checks, and explanations.

What string concatenation covers

The + operator concatenates when at least one operand is a String, and adds when both operands are numeric. Java evaluates left to right, so the position of the first String in the expression decides whether earlier numbers are added or appended. Any primitive concatenated with a String is converted to its text form, and objects are converted using their toString method.

Where students lose points

"1" + 2 + 3 produces "123" while 1 + 2 + "3" produces "33", and mixing these up is the single most common concatenation error. Students also forget that parentheses force the arithmetic to happen first, which is exactly what a question is testing when it shows two nearly identical print statements.

How it shows up on the AP exam

Unit 1 material that appears constantly in output-tracing MCQs, because it lets the exam test evaluation order and type rules in a single short line of code.

For practice use only.

String Concatenation MCQ Practice

AP CSA String concatenation practice: how + mixes String and numeric operands, left-to-right evaluation order, and the output-tracing questions built on it.

Question 1 of 15

Answered 0 of 15

Choose one answer.

Code Tracing 01 - String Concatenation: track the final printed value.

String tag = "ALGO";
int x = 18;
int y = 3;
int z = 5;
System.out.print(tag + (x + y) + z);

All 15 string concatenation questions

Work through the interactive quiz above first. This is the full string concatenation question set with worked solutions, so students can review any question after attempting it.

  1. 1.Code Tracing 01 - String Concatenation: track the final printed value.

    String tag = "ALGO";
    int x = 18;
    int y = 3;
    int z = 5;
    System.out.print(tag + (x + y) + z);
    • ALGO1835
    • ALGO26
    • 215ALGO
    • ALGO215
    Show worked solution

    Correct answer: ALGO215

    The parenthesized addition happens before concatenation; z is appended after the String result already exists.

  2. 2.Code Tracing 12 - String Concatenation: follow the variable updates.

    String label = "PR";
    int a = 26;
    int b = 5;
    int c = 7;
    System.out.print(a + b + label + c);
    • 31PR7
    • 265PR7
    • 38PR
    • PR317
    Show worked solution

    Correct answer: 31PR7

    The first two operands are ints, so they add numerically. Once label is reached, the rest is concatenation.

  3. 3.Code Tracing 28 - String Concatenation: trace the branch and loop path.

    String out = "M";
    out += 38;
    out += (3 + 10);
    System.out.print(out);
    • M3813
    • M38310
    • M51
    • 3813
    Show worked solution

    Correct answer: M3813

    The first += appends a number as text. The parentheses force the second numeric addition before appending.

  4. 4.Code Tracing 39 - String Concatenation: watch the index changes.

    String prefix = "AR";
    int a = 46;
    int b = 5;
    int c = 5;
    System.out.print(prefix + a + (b + c));
    • 46AR10
    • AR4610
    • AR56
    • AR4655
    Show worked solution

    Correct answer: AR4610

    prefix + a starts concatenation. The parenthesized expression is evaluated numerically before it is appended.

  5. 5.Code Tracing 50 - String Concatenation: evaluate the state change step by step.

    String word = "CODING";
    int a = 54;
    int b = 7;
    String result = (a + b) + "-" + word.length();
    System.out.print(result);
    • 55
    • 6-61
    • 61-6
    • 547-6
    Show worked solution

    Correct answer: 61-6

    The arithmetic in parentheses happens first. The hyphen is a String, so the length is appended as text.

  6. 6.What is printed by the following code segment?

    int a = 1;
    int b = 2;
    System.out.print("R" + a + b + " " + (a + b) + " " + a + b);
    • R3 3 3
    • R12 3 3
    • R12 3 12
    • R3 3 12
    Show worked solution

    Correct answer: R12 3 12

    Once a String appears everything to its right concatenates, unless parentheses force the addition first.

  7. 7.What is printed by the following code segment?

    String s = "AP";
    s += 1 + 2;
    s += "" + 1 + 2;
    System.out.print(s);
    • AP1212
    • AP33
    • AP123
    • AP312
    Show worked solution

    Correct answer: AP312

    The first addition happens before the concatenation, giving 3. In the second, the empty string forces both digits to concatenate.

  8. 8.What is printed by the following code segment?

    char c = 'A';
    System.out.print(c + 1);
    System.out.print(" " + c + 1);
    • 66 A1
    • A1 A1
    • 66 66
    • B B1
    Show worked solution

    Correct answer: 66 A1

    A char promotes to its numeric value in arithmetic, but concatenating with a String prints the character itself.

  9. 9.What is printed by the following code segment?

    String s = "abc";
    System.out.print(s + s.length() + s.charAt(0));
    • abc3abc
    • abc3a
    • abc4a
    • abca3
    Show worked solution

    Correct answer: abc3a

    Both the length and the character are appended as text, in the order they appear.

  10. 10.What is printed by the following code segment?

    double d = 5.0;
    System.out.print("v=" + d + 1);
    • v=6.0
    • v=51
    • v=5.01
    • v=6
    Show worked solution

    Correct answer: v=5.01

    The double prints with its decimal point and the 1 is concatenated afterward rather than added.

  11. 11.What is printed by the following code segment?

    String a = "1";
    String b = "2";
    System.out.print(a + b + (a.length() + b.length()));
    • 1222
    • 14
    • 32
    • 122
    Show worked solution

    Correct answer: 122

    The strings concatenate to 12, and the parenthesised sum of the two lengths adds to 2.

  12. 12.What is printed by the following code segment?

    System.out.print(1 + 2 + "3" + 4 + 5);
    • 3345
    • 12345
    • 15
    • 3 345
    Show worked solution

    Correct answer: 3345

    The leading operands are added because both are int, and everything after the String concatenates.

  13. 13.What is printed by the following code segment?

    String s = "";
    for (int i = 3; i >= 1; i--)
    {
        s += i + "-";
    }
    System.out.print(s);
    • 1-2-3-
    • 3-2-1-
    • 321
    • -3-2-1
    Show worked solution

    Correct answer: 3-2-1-

    The loop counts down and appends each value with a trailing separator, so the result ends with a hyphen.

  14. 14.What is printed by the following code segment?

    String s = "x";
    for (int i = 0; i < 3; i++)
    {
        s = s + s;
    }
    System.out.print(s.length());
    • 6
    • 4
    • 8
    • 3
    Show worked solution

    Correct answer: 8

    Each pass doubles the string, so its length goes 2, 4, then 8.

  15. 15.What is printed by the following code segment?

    int n = 5;
    String s = n > 3 ? "big" : "small";
    System.out.print(s + n + (n > 3));
    • big5
    • bigtrue
    • small5true
    • big5true
    Show worked solution

    Correct answer: big5true

    The conditional operator selects big, the int concatenates as text, and the boolean prints as true.