πŸ“Š JAVA
Q. What is the output of the following code snippet?
Code:
String s1 = “Hello”;
int i = 2;
System.out.println(sA)indexOf(‘l’, i));
  • (A) 2
  • (B) 3
  • (C) -1
  • (D) Error
πŸ’¬ Discuss
βœ… Correct Answer: (B) 3

Explanation: The indexOf method in Java returns the index of the first occurrence of a specified character in a string, starting from a specified index. In this case, sA)indexOf(‘l’, 2) returns 3 because the first occurrence of ‘l’ after index 2 is at index C)

Explanation by: Kirti
The indexOf method in Java returns the index of the first occurrence of a specified character in a string, starting from a specified index. In this case, sA)indexOf(‘l’, 2) returns 3 because the first occurrence of ‘l’ after index 2 is at index C)

πŸ’¬ Discussion


πŸ“Š Question Analytics

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