Java字符charCount()与示例
Character.charCount()方法确定表示指定字符(Unicode代码点)所需的char值的数量。如果指定的字符等于或大于0x10000,则该方法返回2。否则,该方法返回1。
示例
现在让我们看一个例子-
import java.lang.*;
public class Demo {
public static void main(String[] args) {
//创建并将值分配给int代码点cp-
int cp = 0x12345;
//创建一个intres-
int res;
//将cp上charCount的结果分配给res-
res = Character.charCount(cp);
String str1 = "It is not a valid supplementary character";
String str2 = "It is a valid supplementary character";
//打印res值
if ( res == 1 ) {
System.out.println( str1 );
} else if ( res == 2 ) {
System.out.println( str2 );
}
}
}输出结果
It is a valid supplementary character
示例
让我们看另一个例子-
import java.lang.*;
public class Demo {
public static void main(String[] args) {
int c = 0x11987;
int res = Character.charCount(c);
System.out.println(res);
}
}输出结果
2
热门推荐
10 圣诞祝福语简短小学
11 祖国七十华诞简短祝福语
12 老师送的祝福语简短
13 生日祝福语大全女生简短
14 祝女性生日祝福语简短
15 牛年女神节祝福语简短
16 情人表白祝福语简短大气
17 老公开业祝福语简短
18 官宣新年祝福语简短