Q. What will be the output?
String str1 = "abcde";
System.out.println(str1.substring(1, 3));

  • (A) abc
  • (B) bc
  • (C) bcd
  • (D) bcd D. abcd
πŸ’¬ Discuss
βœ… Correct Answer: (B) bc
Explanation: substring() method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or upto endIndex - 1 if second argument is given.
Explanation by: Bhagwan Das
substring() method has two variants and returns a new string that is a substring of this string. The substring begins with the character at the specified index and extends to the end of this string or upto endIndex - 1 if second argument is given.

πŸ’¬ Discussion


πŸ“Š Question Analytics

πŸ‘οΈ
89
Total Visits
πŸ“½οΈ
1 y ago
Published
πŸŽ–οΈ
Bhagwan Das
Publisher
πŸ“ˆ
90%
Success Rate