Computer Applications

What is the output of the following statement:

“MONOPOLY”.lastIndexOf(‘O’);

  1. 1
  2. 3
  3. 2
  4. 5

Java

Java String Handling

7 Likes

Answer

5

Reason — In the string "MONOPOLY", the character 'O' occurs at indexes 1, 3, and 5 (indexing starts from 0). The lastIndexOf('O') method returns the last occurrence of 'O', which is at index 5.

Answered By

4 Likes


Related Questions