Java Character charCount() method

The charCount() method of character class is used to determine the total number of char values needed to represent the specified character. As the name suggests, it counts the total char values.

Syntax

Parameter

The method requires a codePoint. A codePoint is a character to be tested.

Return Value

If the given character is equal to or greater than 0X10000, the method returns 2. Otherwise the method returns 1.

Example 1

Output:

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

Example 2

Output:

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

Example 3

Output:

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