The output from the following code is 123
because substring
takes from beginIndex to EndIndex - 1. However, I am surprised how char
Others already explainted why it works but note that it is bad practice to use char variables for indices, since they have different associated semantics and thus it is confusing to use a char as an index.
Use chars only to store character data and probably better: try to avoid char altogether, since they are not even wide enough to store every character (see Unicode and code point discussion). Use int to store character code points instead.