/**
* Returns a string that is a substring of this string. The
* substring begins at the specified {@code beginIndex} and
* extends to the character at index {@code endIndex - 1}.
* Thus the length of the substring is {@code endIndex-beginIndex}.
* <p>
* Examples:
* <blockquote><pre>
* "hamburger".substring(4, 8) returns "urge"
* "smiles".substring(1, 5) returns "mile"
* </pre></blockquote>
*
* @param beginIndex the beginning index, inclusive.
* @param endIndex the ending index, exclusive.
* @return the specified substring.
* @exception IndexOutOfBoundsException if the
* {@code beginIndex} is negative, or
* {@code endIndex} is larger than the length of
* this {@code String} object, or
* {@code beginIndex} is larger than
* {@code endIndex}.
*/
public String substring
(int beginIndex,
int endIndex
) { if (beginIndex < 0) {
}
if (endIndex > value.length) {
}
int subLen = endIndex - beginIndex;
if (subLen < 0) {
}
return ((beginIndex == 0) && (endIndex == value.length)) ? this
: new String(value, beginIndex, subLen
); }
CiAgICAvKioKICAgICAqIFJldHVybnMgYSBzdHJpbmcgdGhhdCBpcyBhIHN1YnN0cmluZyBvZiB0aGlzIHN0cmluZy4gVGhlCiAgICAgKiBzdWJzdHJpbmcgYmVnaW5zIGF0IHRoZSBzcGVjaWZpZWQge0Bjb2RlIGJlZ2luSW5kZXh9IGFuZAogICAgICogZXh0ZW5kcyB0byB0aGUgY2hhcmFjdGVyIGF0IGluZGV4IHtAY29kZSBlbmRJbmRleCAtIDF9LgogICAgICogVGh1cyB0aGUgbGVuZ3RoIG9mIHRoZSBzdWJzdHJpbmcgaXMge0Bjb2RlIGVuZEluZGV4LWJlZ2luSW5kZXh9LgogICAgICogPHA+CiAgICAgKiBFeGFtcGxlczoKICAgICAqIDxibG9ja3F1b3RlPjxwcmU+CiAgICAgKiAiaGFtYnVyZ2VyIi5zdWJzdHJpbmcoNCwgOCkgcmV0dXJucyAidXJnZSIKICAgICAqICJzbWlsZXMiLnN1YnN0cmluZygxLCA1KSByZXR1cm5zICJtaWxlIgogICAgICogPC9wcmU+PC9ibG9ja3F1b3RlPgogICAgICoKICAgICAqIEBwYXJhbSAgICAgIGJlZ2luSW5kZXggICB0aGUgYmVnaW5uaW5nIGluZGV4LCBpbmNsdXNpdmUuCiAgICAgKiBAcGFyYW0gICAgICBlbmRJbmRleCAgICAgdGhlIGVuZGluZyBpbmRleCwgZXhjbHVzaXZlLgogICAgICogQHJldHVybiAgICAgdGhlIHNwZWNpZmllZCBzdWJzdHJpbmcuCiAgICAgKiBAZXhjZXB0aW9uICBJbmRleE91dE9mQm91bmRzRXhjZXB0aW9uICBpZiB0aGUKICAgICAqICAgICAgICAgICAgIHtAY29kZSBiZWdpbkluZGV4fSBpcyBuZWdhdGl2ZSwgb3IKICAgICAqICAgICAgICAgICAgIHtAY29kZSBlbmRJbmRleH0gaXMgbGFyZ2VyIHRoYW4gdGhlIGxlbmd0aCBvZgogICAgICogICAgICAgICAgICAgdGhpcyB7QGNvZGUgU3RyaW5nfSBvYmplY3QsIG9yCiAgICAgKiAgICAgICAgICAgICB7QGNvZGUgYmVnaW5JbmRleH0gaXMgbGFyZ2VyIHRoYW4KICAgICAqICAgICAgICAgICAgIHtAY29kZSBlbmRJbmRleH0uCiAgICAgKi8KICAgIHB1YmxpYyBTdHJpbmcgc3Vic3RyaW5nKGludCBiZWdpbkluZGV4LCBpbnQgZW5kSW5kZXgpIHsKICAgICAgICBpZiAoYmVnaW5JbmRleCA8IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFN0cmluZ0luZGV4T3V0T2ZCb3VuZHNFeGNlcHRpb24oYmVnaW5JbmRleCk7CiAgICAgICAgfQogICAgICAgIGlmIChlbmRJbmRleCA+IHZhbHVlLmxlbmd0aCkgewogICAgICAgICAgICB0aHJvdyBuZXcgU3RyaW5nSW5kZXhPdXRPZkJvdW5kc0V4Y2VwdGlvbihlbmRJbmRleCk7CiAgICAgICAgfQogICAgICAgIGludCBzdWJMZW4gPSBlbmRJbmRleCAtIGJlZ2luSW5kZXg7CiAgICAgICAgaWYgKHN1YkxlbiA8IDApIHsKICAgICAgICAgICAgdGhyb3cgbmV3IFN0cmluZ0luZGV4T3V0T2ZCb3VuZHNFeGNlcHRpb24oc3ViTGVuKTsKICAgICAgICB9CiAgICAgICAgcmV0dXJuICgoYmVnaW5JbmRleCA9PSAwKSAmJiAoZW5kSW5kZXggPT0gdmFsdWUubGVuZ3RoKSkgPyB0aGlzCiAgICAgICAgICAgICAgICA6IG5ldyBTdHJpbmcodmFsdWUsIGJlZ2luSW5kZXgsIHN1Ykxlbik7CiAgICB9
Main.java:24: error: class, interface, or enum expected
public String substring(int beginIndex, int endIndex) {
^
Main.java:27: error: class, interface, or enum expected
}
^
Main.java:30: error: class, interface, or enum expected
}
^
Main.java:32: error: class, interface, or enum expected
if (subLen < 0) {
^
Main.java:34: error: class, interface, or enum expected
}
^
Main.java:37: error: class, interface, or enum expected
}
^
6 errors