Add the code
Add the following code to the ToTitleCase.java
file to convert the specified Unicode code point character argument to titlecase:
import java.util.Scanner;
public class ToTitleCase {
public static void main(String[] args) {
// Example 1
int cp1 = 78;
int cp2 = 102;
int cp3 = 66;
int cp4 = 48;
int cp5 = 1232;
char ch1 = Character.toTitleCase(cp1);
char ch2 = Character.toTitleCase(cp2);
char ch3 = Character.toTitleCase(cp3);
char ch4 = Character.toTitleCase(cp4);
char ch5 = Character.toTitleCase(cp5);
System.out.println("Example 1:");
System.out.println("The titlecase character of 78 is :"+ch1);
System.out.println("The titlecase character of 102 is :"+ch2);
System.out.println("The titlecase character of 66 is :"+ch3);
System.out.println("The titlecase character of 48 is :"+ch4);
System.out.println("The titlecase character of 1232 is :"+ch5);
// Example 2
try {
System.out.println("\nExample 2:");
System.out.print("Enter the Unicode codepoint: ");
Scanner sc = new Scanner(System.in);
int cp = sc.nextInt();
char cc = Character.toTitleCase(cp);
System.out.println("The titlecase character is : "+cc);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
The first example converts various code points to their equivalent titlecase characters, while the second example is a user-defined code block which takes input from the user and returns the titlecase character of the input Unicode code point value.