Home / Programming MCQs / JAVA MCQs / Question

K

Kirti • 10.37K Points
Tutor II

Q. What is the output of the following code snippet?

Code:
String s1 = “Hello”;
System.out.println(sA)indexOf(‘z’));
(A) -1
(B) 0
(C) Error
(D) None of these
Explanation by: Kirti
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.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.