Fun with Characters
Complete the checkCharacter() method which has 2 parameters: A String, and a specified index (int). The method checks the character at the specified index of the String parameter and returns a String based on the type of character at that location indicating if the character is a letter, digit, whitespace, or unknown character.

Ex: The method calls below with the given arguments will return the following Strings:
checkCharacter("happy birthday", 2) returns "Character 'p' is a letter"
checkCharacter("happy birthday", 5) returns "Character ' ' is a white space"
checkCharacter("happy birthday 2 you", 15) returns "Character '2' is a digit"
checkCharacter("happy birthday!", 14) returns "Character '!' is unknown"


CODE:
public class LabProgram {
public static String checkCharacter(String inputString, int index){
/* Type your code here. */
}

public static void main(String[] args) {
System.out.println(checkCharacter("happy birthday", 2));
System.out.println(checkCharacter("happy birthday", 5));
System.out.println(checkCharacter("happy birthday 2 you", 15));
System.out.println(checkCharacter("happy birthday!", 14));
}
}

Respuesta :

The program is an illustration of conditional statements.

Conditional statements are statements whose execution is dependent on the truth value of the condition.

The checkCharacter() method in Java, where comments are used to explain each line is as follows:

//This defines the checkCharacter() method

public static String checkCharacter(String inputString, int index){

  //This checks if the character at the index, is a digit

  if(Character.isDigit(inputString.charAt(index))){

      //If yes, it returns "Digit"  

      return "Character "+inputString.charAt(index)+" is a digit";

  }

  //This checks if the character at the index, is a letter

  else if(Character.isLetter(inputString.charAt(index))){

      //If yes, it returns "letter"

      return "Character "+inputString.charAt(index)+" is a Letter";

  }

  //This checks if the character at the index, is a white space

  else if(inputString.charAt(index) ==' '){

      //If yes, it returns "white space"

      return "Character "+inputString.charAt(index)+" is a white space";

  }

  #If all the above conditions are false

   else{

      //If yes, it returns "unknown character"

      return "Character "+inputString.charAt(index)+" is an unknown character";

  }

}

The string to return depends on the character at the index.

Read more about similar programs at:

https://brainly.com/question/25127567