IDNLearn.com offers a unique blend of expert answers and community-driven knowledge. Get step-by-step guidance for all your technical questions from our dedicated community members.
Consider the following method substringFound, which is intended to return true if a substring, key, is located at a specific index of the string phrase. Otherwise, it should return false.
public boolean substringFound(String phrase, String key, int index)
{
String part = phrase.substring(index, index + key.length());
return part.equals(key);
}
Which of the following is the best precondition for index so that the method will return the appropriate result in all cases and a runtime error can be avoided?
A. 0 <= index < phrase.length()
B. 0 <= index < key.length()
C. 0 <= index < phrase.length() + key.length()
D. 0 <= index < phrase.length() - key.length()
E. 0 <= index < phrase.length() - index
Thank you for using this platform to share and learn. Keep asking and answering. We appreciate every contribution you make. IDNLearn.com is committed to your satisfaction. Thank you for visiting, and see you next time for more helpful answers.