Java Character.lowSurrogate()
方法
原文:https://www.studytonight.com/java-wrapper-class/java-character-lowsurrogate-method
Java lowSurrogate()
方法是 Character 类的一部分。此方法返回代理项对的尾部代理项(低代理项代码单位),代表 UTF-16 编码中指定的补充字符(Unicode 代码点)。
语法:
public static char lowSurrogate(int codePoint)
参数:
传递的参数是 Unicode 代码点字符,其尾部代理项将被返回。
返回:
返回用于表示 UTF-16 编码中指定代码点字符的尾部代理代码单元。
例 1:
这里,为指定的 Unicode 代码点字符返回尾部代理字符。
public class StudyTonight
{
public static void main(String[] args)
{
int cp1 = 67;
int cp2 = 88;
int cp3 = 119;
int cp4 = 202;
int cp5 = 1232;
char ch1 = Character.lowSurrogate(cp1);
char ch2 = Character.lowSurrogate(cp2);
char ch3 = Character.lowSurrogate(cp3);
char ch4 = Character.lowSurrogate(cp4);
char ch5 = Character.lowSurrogate(cp5);
System.out.println("The trailing surrogate for " +(char)cp1 +" is "+ch1);
System.out.println("The trailing surrogate for " +(char)cp2 +" is "+ch2);
System.out.println("The trailing surrogate for " +(char)cp3 +" is "+ch3);
System.out.println("The trailing surrogate for " +(char)cp4 +" is "+ch4);
System.out.println("The trailing surrogate for " +(char)cp5 +" is "+ch5);
}
}
C 的尾随代孕是? X 的尾随代孕是? w 的尾随代孕是? 的尾随代理是? 的尾随代孕?是吗?
例 2:
这里有一个用户定义的例子,任何使用这段代码的人都可以输入自己选择的值,并获得等效的输出。
import java.util.Scanner;
public class StudyTonight
{
public static void main(String[] args)
{
try
{
System.out.print("Enter the Unicode character: ");
Scanner sc = new Scanner(System.in);
int cp = sc.nextInt();
char ch = Character.lowSurrogate(cp);
System.out.println("The trailing surrogate for " +(char)cp +" is "+ch);
}
catch(Exception e)
{
System.out.println("Invalid Input!!");
}
}
}
输入 Unicode 字符:66 B 的尾随代理项是? *输入 Unicode 字符:34343 的尾随代理?是吗?
实时示例:
在这里,您可以测试实时代码示例。您可以为不同的值执行示例,甚至可以编辑和编写您的示例来测试 Java 代码。