...
The following function takes a string and returns true if it consists of a capital letter succeeded by lowercase letters. To handle corner cases, it merely wraps the code in a try/catch block and reports any excepts exceptionss that arise.
Code Block | ||
---|---|---|
| ||
boolean isCapitalized(String s) {
try {
if (s.equals("")) {
return true;
}
String first = s.substring( 0, 1);
String rest = s.substring( 1);
return (first.equals( first.toUpperCase()) &&
rest.equals( rest.toLowerCase()));
} catch (RuntimeException exception) {
ExceptionReporter.report( exception);
}
return false;
}
|
...