A

Admin • 832.52K Points
Coach

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

Code:
String s1 = “Hello”;
System.out.println(sA)substring(1, 3));
  • (A) el
  • (B) He
  • (C) ll
  • (D) Error
  • Correct Answer - Option(A)
  • Views: 23
  • Filed under category Java
  • Hashtags:

Explanation by: Admin

The substring method in Java can also take a second parameter, which specifies the end index of the substring (exclusive). In this case, sA)substring(1, 3) returns “el”.

You must be Logged in to update hint/solution

Discusssion

Login to discuss.

Be the first to start discuss.