KnowledgeBoat Logo

Computer Applications

The output of the statement "CONCENTRATION".indexOf('T') is:

  1. 9
  2. 7
  3. 6
  4. (-1)

Java String Handling

ICSE 2024

3 Likes

Answer

6

Reason — The method indexOf(char ch) in Java returns the index of the first occurrence of the specified character ch in the string. If the character is not found, it returns -1.

Consider the string:
"CONCENTRATION"

Let’s count the characters by their index (Java uses zero-based indexing):

CONCENTRATION
0123456789101112

The first occurrence of the character 'T' is at index 6.

Thus, the output of the statement "CONCENTRATION".indexOf('T') is 6.

Answered By

2 Likes


Related Questions