String Methods

AP Computer Science A· difficulty 3/5

public static String go() {
    String s = "abcdef";
    s = s.substring(1, 4) + s.charAt(5);
    return s.toUpperCase();
}
// Call: System.out.println(go());

What is printed?

  • A

    BCDE

  • B

    BCDEF

  • C

    BCDF

    check_circle
  • D

    ABCF

Explanation

substring(1,4) = "bcd". charAt(5) = 'f'. Concatenation -> "bcdf". toUpperCase -> "BCDF".

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

Related questions