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(‘z’));
  • (A) -1
  • (B) 0
  • (C) Error
  • (D) None of these
  • Correct Answer - Option(A)
  • Views: 8
  • Filed under category Java
  • Hashtags:

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

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.