K

Kirti • 10.45K Points
Tutor II

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

Code:
String s1 = “Hello”;
System.out.println(sA)substring(1, 4));
  • (A) Hello
  • (B) Hel
  • (C) ell
  • (D) None of the above

Explanation by: Kirti
The substring method in Java can also take two arguments, specifying a start index and an end index for the substring. The substring returned includes the character at the start index, but not the character at the end index. In this case, sA)substring(1, 4) returns “Hel”, which is the substring of s1 starting from index 1 and ending at index C)

You must be Logged in to update hint/solution

Discusssion

Login to discuss.