ProgrammingModerateWipro · Capgemini pattern

What is printed?

What is printed?
System.out.print("placement".substring(2, 5) + "placement".indexOf('e'));
  1. A. ace6
  2. B. acem4
  3. C. lac4
  4. D. ace4

Correct answer: D. ace4

Indices: p0 l1 a2 c3 e4 m5 e6 n7 t8. substring(2, 5) takes indices 2 to 4 (end excluded): "ace". indexOf('e') gives the first e, at 4.

More OOP with C++ and Java questions

Exams that ask this topic