Computer Applications

The output of the statement of "TIGER".indexOf('G') is:

  1. 3
  2. 2
  3. -1
  4. 0

Java String Handling

1 Like

Answer

2

Reason — The indexOf() method in Java returns the position (index) of the first occurrence of the specified character in the string.
In the string "TIGER":

  • T is at index 0
  • I is at index 1
  • G is at index 2

So, "TIGER".indexOf('G') returns 2.

Answered By

1 Like


Related Questions