Java Character lowSurrogate Method

JavaJavaBeginner
Practice Now

Introduction

This lab will walk you through the usage of the Java lowSurrogate() Method. You will learn what this method does, what are its parameters and return type, and how it can be used in Java programming.


Skills Graph

%%%%{init: {'theme':'neutral'}}%%%% flowchart RL java(("`Java`")) -.-> java/ObjectOrientedandAdvancedConceptsGroup(["`Object-Oriented and Advanced Concepts`"]) java(("`Java`")) -.-> java/BasicSyntaxGroup(["`Basic Syntax`"]) java(("`Java`")) -.-> java/DataStructuresGroup(["`Data Structures`"]) java(("`Java`")) -.-> java/StringManipulationGroup(["`String Manipulation`"]) java(("`Java`")) -.-> java/SystemandDataProcessingGroup(["`System and Data Processing`"]) java/ObjectOrientedandAdvancedConceptsGroup -.-> java/class_methods("`Class Methods`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/modifiers("`Modifiers`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/oop("`OOP`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/packages_api("`Packages / API`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/user_input("`User Input`") java/ObjectOrientedandAdvancedConceptsGroup -.-> java/wrapper_classes("`Wrapper Classes`") java/BasicSyntaxGroup -.-> java/identifier("`Identifier`") java/DataStructuresGroup -.-> java/arrays("`Arrays`") java/BasicSyntaxGroup -.-> java/data_types("`Data Types`") java/BasicSyntaxGroup -.-> java/operators("`Operators`") java/BasicSyntaxGroup -.-> java/output("`Output`") java/StringManipulationGroup -.-> java/strings("`Strings`") java/BasicSyntaxGroup -.-> java/type_casting("`Type Casting`") java/BasicSyntaxGroup -.-> java/variables("`Variables`") java/SystemandDataProcessingGroup -.-> java/system_methods("`System Methods`") subgraph Lab Skills java/class_methods -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/modifiers -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/oop -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/packages_api -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/user_input -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/wrapper_classes -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/identifier -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/arrays -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/data_types -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/operators -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/output -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/strings -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/type_casting -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/variables -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} java/system_methods -.-> lab-117574{{"`Java Character lowSurrogate Method`"}} end

Import java.util.Scanner and java.lang.Character

Import the java.util.Scanner and java.lang.Character packages at the top of your Java file, so that you can use their classes in your code.

import java.util.Scanner;
import java.lang.Character;

Create a main() method

Create a main() method inside your class. The main() method is the entry point of your Java program, and all the code written inside this method will be executed when the program is run.

public static void main(String[] args) {

}

Take user input

Take a Unicode character as an input from the user. You can use the Scanner class to take user input. Initialize a new Scanner object and use the nextInt() method to take an integer input from the user.

Scanner input = new Scanner(System.in);
System.out.print("Enter a Unicode character: ");
int unicode = input.nextInt();

Get the trailing surrogate

Use the lowSurrogate() method of the Character class to get the trailing surrogate of the Unicode character entered by the user. Pass the Unicode character to the lowSurrogate() method as a parameter. The method will return the trailing surrogate as a char type.

char trailingSurrogate = Character.lowSurrogate(unicode);

Display the output

Display the Unicode character entered by the user and its corresponding trailing surrogate using the println() method of the System.out object.

System.out.println("The trailing surrogate of " + (char)unicode + " is " + trailingSurrogate);

Compile and run the program

Compile the Java program using the following command in the terminal:

javac LowSurrogateDemo.java

Run the program using the following command:

java LowSurrogateDemo

Enter a Unicode character when prompted and press Enter to get the trailing surrogate.

Enter a Unicode character: 128169
The trailing surrogate of 🚩 is �

Summary

In this lab, you have learned how to use the Java lowSurrogate() Method to get the trailing surrogate of a Unicode character. You have learned how to take user input, pass it to the method, display the output, compile and run the program. This method is useful when you need to manipulate Unicode strings in your Java programs.

Other Java Tutorials you may like