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
πŸ’¬ Discuss
βœ… Correct Answer: (A) 2
Explanation: 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.
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.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
309
Total Visits
πŸ“½οΈ
3 y ago
Published
πŸŽ–οΈ
Kirti
Publisher
πŸ“ˆ
88%
Success Rate