Q. What is the output of the following code snippet?
Code:
String s1 = “Hello”; int i = 2; System.out.println(sA)indexOf(‘l’, i));
β
Correct Answer: (B)
3
Explanation: The indexOf method in Java returns the index of the first occurrence of a specified character in a string, starting from a specified index. In this case, sA)indexOf(‘l’, 2) returns 3 because the first occurrence of ‘l’ after index 2 is at index C)