This is the requested code in java.
public class <em>CharTest</em> {
public static String checkCharacter(String text, int index) {
if (0 <= index && index <= text.length()) {
char ch = text.charAt(index);
if (Character.isLetter(ch)) {
return ch + " is a letter";
} else if (Character.isDigit(ch)) {
return ch + " is a digit";
} else if (Character.isWhitespace(ch)) {
return ch + " is a whitespace character";
} else {
return ch + " is an unknown type of character";
}
} else {
return "index " + index.toString() + " is out of range";
} // <em>end if</em>
} // <em>end function checkChar()</em>
public static void <em>main</em>(String[] args) {
// <em>Test the three samples from the specification.</em>
System.out.println(<em>checkCharacter</em>("happy birthday", 2));
System.out.println(<em>checkCharacter</em>("happy birthday", 5));
System.out.println(<em>checkCharacter</em>("happy birthday 2 you", 15));
} // <em>end function main()</em>
} // <em>end class CharTest</em>
The function <em>checkcharacter</em>(text, index) returns a string value describing the kind of character found at the position in text specified by index; whether it was a letter, digit, whitespace, or an unknown kind of character.
How it does that is to make use of respective functions defined within the Character class in java. That is
- isLetter(char) returns a bool specifying if the char parameter is a letter.
- isDigit(char) returns a bool specifying if the char parameter is a digit.
- isWhitespace(char) returns a bool specifying if the char parameter is a whitespace character.
It calls these functions in an if statement. These else part of the if statement is then executed if the character is neither a <em>letter</em>, <em>digit</em>, or <em>whitespace</em>.
Finally, the function main() calls <em>checkCharacter</em>() three times to test the function and return the results to the console.
Another example of a java program on characters is found in the link below
brainly.com/question/15061607