String Methods

AP Computer Science A· difficulty 4/5

String s = "abcdef";
String t = s.substring(1, 4).substring(1);
System.out.println(t);

What is printed?

  • A

    cd

    check_circle
  • B

    bc

  • C

    bcd

  • D

    cde

Explanation

s.substring(1, 4) is "bcd"; calling substring(1) on "bcd" gives "cd".

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

Related questions