K

Kirti • 10.45K Points
Tutor II

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

Code:
String s1 = “Hello”;
System.out.println(sA)indexOf(‘l’));
  • (A) 2
  • (B) 3
  • (C) 4
  • (D) None of these
  • Correct Answer - Option(A)
  • Views: 183
  • Filed under category JAVA

Explanation by: Kirti
The indexOf method in Java returns the index of the first occurrence of a specified character in a string. In this case, sA)indexOf(‘l’) returns 2, which is the index of the first “l” in the string.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.


Question analytics