Let's break down the two string method operations in Java for the string "MISSISSIPPI":
1. "MISSISSIPPI".indexOf('S')
The indexOf('S')
method returns the index of the first occurrence of the character 'S' in the string "MISSISSIPPI".
So, "MISSISSIPPI".indexOf('S')
returns 2.
2. "MISSISSIPPI".lastIndexOf('I')
The lastIndexOf('I')
method returns the index of the last occurrence of the character 'I' in the string "MISSISSIPPI".
- From the same index mapping, the last occurrence of 'I' is at index 10.
So, "MISSISSIPPI".lastIndexOf('I')
returns 10.
Addition Operation
Now, adding these two results together:
indexOf('S') + lastIndexOf('I')
= 2 + 10
= 12
So, the correct answer is:
12