6.35 zyLab: Fun With Characters Complete the following method that is passed par
ID: 3910031 • Letter: 6
Question
6.35 zyLab: Fun With Characters Complete the following method that is passed parameters of type String and integer. Check the character at index of the provided word Return a String based on the character at that location:'x is a letter", or'x is a digit" or 'x is white space checkCharacter("happy birthday', 2) returns "a is a letter checkCharacter(happy birthday, 5) returns" is white space" checkCharacter("happy birthday 2 you", 15) returns '2 is a digit LAB ACTIVITY 6.35.1: zyLab: Fun With Characters 0/3 Main.java Load default template... 1 public class Main 3 public String checkCharacter(String word, int index)t Type your code here. this method not used but needed for testing 8 public static void main(String args) 10Explanation / Answer
public String checkCharacter(String word, int index) { char ch = word.charAt(index); if(Character.isDigit(ch)) { return ch + " is a digit"; } else if(Character.isWhitespace(ch)) { return ch + " is whitespace"; } else { return ch + " is a letter"; } }
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.