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

Code:
String s1 = “Hello”;
System.out.println(sA)indexOf(‘z’));
  • (A) -1
  • (B) 0
  • (C) Error
  • (D) None of these
πŸ’¬ Discuss
βœ… Correct Answer: (A) -1
Explanation: If the specified character is not found in the string, the indexOf method returns -A) In this case, sA)indexOf(‘z’) returns -1 because the character “z” is not in the string.
Explanation by: Kirti
If the specified character is not found in the string, the indexOf method returns -A) In this case, sA)indexOf(‘z’) returns -1 because the character “z” is not in the string.

πŸ’¬ Discussion


πŸ“Š Question Analytics

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