1(iii)
The output of the statement "CONCENTRATION".indexOf('T') is:
- (a)9
- (b)7
- (c)6
- (d)(-1)
Show SolutionHide Solution↓
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):
| C | O | N | C | E | N | T | R | A | T | I | O | N |
|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 |
The first occurrence of the character 'T' is at index 6.
Thus, the output of the statement "CONCENTRATION".indexOf('T') is 6.