Answer:
* ** *** **** *****
More Tricky Rules
As with the other substring method, this one
public String substring(int beginIndex, int endIndex )
creates a new string. The original string is not changed.
There are some tricky rules.
Essentially, the rules say that if the indexes make no sense,
a IndexOutOfBoundsException is thrown.
- If
beginIndexis negative value, anIndexOutOfBoundsExceptionis thrown. - If
beginIndexis larger thanendIndex, anIndexOutOfBoundsExceptionis thrown. - If
endIndexis larger than the length, anIndexOutOfBoundsExceptionis thrown. - If
beginIndexequalsendIndex, and both are within range, then an empty string is returned.
Usually, when an exception is thrown your program halts. Future chapters discuss how to deal with exceptions
QUESTION 21:
Decide on what string is formed by the following expressions: