If it weren't a homework, you could use existing methods such as Character.isDigit(char)
, Character.isUpperCase(char)
and Character.isLowerCase(char)
which are a bit "smarter", because they don't operate only in ASCII, but also in various charsets.
static final char[] VOWELS = { 'a', 'e', 'i', 'o', 'u', 'A', 'E', 'I', 'O', 'U' };
static boolean isVowel(char ch) {
for (char vowel : VOWELS) {
if (vowel == ch) {
return true;
}
}
return false;
}
static boolean isDigit(char ch) {
return ch >= '0' && ch <= '9';
}
static boolean isLowerCase(char ch) {
return ch >= 'a' && ch <= 'z';
}
static boolean isUpperCase(char ch) {
return ch >= 'A' && ch <= 'Z';
}