Q. What is the output of the following code snippet?
Code:String s1 = “Hello”; System.out.println(sA)indexOf(‘z’));
β
Correct Answer: (A)
-1
Explanation: If the specified character is not found in the string, the indexOf method returns -A) In this case, sA)indexOf(‘z’) returns -1 because the character “z” is not in the string.