Java Character charCount() 方法

2024 年 11 月 6 日 | 阅读 2 分钟

character 类中的 charCount() 方法用于确定表示指定字符所需的 char 值总数。顾名思义,它计算 char 值的总数。

语法

参数

该方法需要一个 codePoint。CodePoint 是要测试的字符。

返回值

如果给定的字符等于或大于 0X10000,则该方法返回 2。否则,该方法返回 1。

示例 1

输出

The first object 59 can be represented by 1 char values
The second object 1546719 can be represented by 2 char values

示例 2

输出

The value comes to be:
1
The value comes to be:
1
The value comes to be:
2

示例 3

输出

Enter the first number
67
The value comes to be: 1
Enter the second number
78
The value comes to be:   1
Enter the third number
2456789
The value comes to be:  2