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

Explanation: The lastIndexOf method in Java returns the index of the last occurrence of a specified character in a string, starting from a specified index. In this case, sA)lastIndexOf(‘l’, 2) returns 2 because the last occurrence of ‘l’ before index 2 is at index B)

Explanation by: Kirti
The lastIndexOf method in Java returns the index of the last occurrence of a specified character in a string, starting from a specified index. In this case, sA)lastIndexOf(‘l’, 2) returns 2 because the last occurrence of ‘l’ before index 2 is at index B)

πŸ’¬ Discussion


πŸ“Š Question Analytics

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