A

Admin • 828.03K Points
Coach

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: 10
  • Filed under category Java
  • Hashtags:

Explanation by: Admin
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.

Be the first to start discuss.