In order to test the toTitleCase(char ch)
method, we need to accept user input. We can do this using the Scanner
class provided by Java.
import java.util.Scanner;
public class TitleCaseExample {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("Enter a character: ");
char ch = scanner.next().charAt(0);
scanner.close();
}
}
In this code, we create a new Scanner
object to read user input from the terminal. We then prompt the user to enter a character and read the input using the scanner.next().charAt(0)
method call. This call reads a string input from the user and returns the first character of that string.