Java OCA OCP Practice Question 3191

Question

What will be written to the standard output when the following program is run?

public class Main {
  public static void main(String[] args) {
    String word = "restructure";
    System.out.println(word.substring(2, 3));
  }
}

Select the one correct answer.

  • (a) est
  • (b) es
  • (c) str
  • (d) st
  • (e) s


(e)

Note

Giving parameters (2, 3) to the method substring() constructs a string consisting of the characters between positions 2 and 3 of the original string.

The positions are indexed in the following manner: position 0 is immediately before the first character of the string, position 1 is between the first and the second character, position 2 is between the second and the third character, and so on.




PreviousNext

Related