Multiple choice

String s = “Welcome To Java” s.lastIndexOf(“Java”,5);

What is the result of the given statements?

    • 1
  1. 11

  2. 6

  3. Compiler error : method lastIndexOf() not declared

  4. Compiler error : parameters to method not sufficient

Reveal answer Fill a bubble to check yourself
A Correct answer
Explanation

lastIndexOf(String s, index i) method return the last occurrence of string "s" before the index value i. it Return -1 if string not found. So here the string to find is “Java” before the index value 5 which means before the character "m". but string “java” is not present before the index 5 i.e character "m" .so it will return -1. So this is the correct answer.