String Objects: Concatenation, Literals, and More

AP Computer Science A· difficulty 4/5

public static String run() {
    String s = "Programming";
    String t = s.substring(0, 4) + s.substring(7);
    return t.replace('m', 'X');
}
// Call: System.out.println(run());

What is printed?

  • A

    ProgXmin

  • B

    ProgXing

    check_circle
  • C

    ProgXXing

  • D

    ProgaXXing

Explanation

substring(0,4)="Prog". substring(7)="ming". Concat = "Progming". replace 'm'->'X' = "ProgXing".

Want 10 more like this — adaptive to your weak spots?

Related questions