String Methods

AP Computer Science A· difficulty 3/5

String s = "computer";
System.out.println(s.substring(2, 5));

What is printed?

  • A

    mput

  • B

    mpu

    check_circle
  • C

    omp

  • D

    ompu

Explanation

substring(2, 5) returns characters at indices 2, 3, and 4 (the end index is exclusive), which is "mpu".

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

Related questions