Write the Java code
In the GetTypeLab.java
file, write the following Java code:
import java.util.Scanner;
public class GetTypeLab {
public static void main(String[] args) {
try {
System.out.println("Enter the Unicode codepoint character:");
Scanner sc = new Scanner(System.in);
int cp = sc.nextInt();
int type = Character.getType(cp);
switch (type) {
case Character.COMBINING_SPACING_MARK:
System.out.println("Combining Spacing Mark");
break;
case Character.CONNECTOR_PUNCTUATION:
System.out.println("Connector Punctuation");
break;
case Character.CONTROL:
System.out.println("Control");
break;
case Character.CURRENCY_SYMBOL:
System.out.println("Currency Symbol");
break;
case Character.DASH_PUNCTUATION:
System.out.println("Dash Punctuation");
break;
case Character.DECIMAL_DIGIT_NUMBER:
System.out.println("Decimal Digit Number");
break;
case Character.ENCLOSING_MARK:
System.out.println("Enclosing Mark");
break;
case Character.END_PUNCTUATION:
System.out.println("End Punctuation");
break;
case Character.FINAL_QUOTE_PUNCTUATION:
System.out.println("Final Quote Punctuation");
break;
case Character.FORMAT:
System.out.println("Format");
break;
case Character.INITIAL_QUOTE_PUNCTUATION:
System.out.println("Initial Quote Punctuation");
break;
case Character.LETTER_NUMBER:
System.out.println("Letter Number");
break;
case Character.LINE_SEPARATOR:
System.out.println("Line Separator");
break;
case Character.LOWERCASE_LETTER:
System.out.println("Lowercase Letter");
break;
case Character.MATH_SYMBOL:
System.out.println("Math Symbol");
break;
case Character.MODIFIER_LETTER:
System.out.println("Modifier Letter");
break;
case Character.MODIFIER_SYMBOL:
System.out.println("Modifier Symbol");
break;
case Character.NON_SPACING_MARK:
System.out.println("Non-Spacing Mark");
break;
case Character.OTHER_LETTER:
System.out.println("Other Letter");
break;
case Character.OTHER_NUMBER:
System.out.println("Other Number");
break;
case Character.OTHER_PUNCTUATION:
System.out.println("Other Punctuation");
break;
case Character.OTHER_SYMBOL:
System.out.println("Other Symbol");
break;
case Character.PARAGRAPH_SEPARATOR:
System.out.println("Paragraph Separator");
break;
case Character.PRIVATE_USE:
System.out.println("Private Use");
break;
case Character.SPACE_SEPARATOR:
System.out.println("Space Separator");
break;
case Character.START_PUNCTUATION:
System.out.println("Start Punctuation");
break;
case Character.SURROGATE:
System.out.println("Surrogate");
break;
case Character.TITLECASE_LETTER:
System.out.println("Titlecase Letter");
break;
case Character.UNASSIGNED:
System.out.println("Unassigned");
break;
case Character.UPPERCASE_LETTER:
System.out.println("Uppercase Letter");
break;
}
} catch (Exception e) {
System.out.println("Invalid input.");
}
}
}
The Java code prompts the user to enter a Unicode codepoint character, uses the getType()
method to get the general category of the character, and prints out the corresponding category.