Java Character getNumericValue() MethodThe getNumericValue() method of character class returns the int value of the specified character. If the character does not have any int value, -1 is returned. If the character has a numeric value that cannot be represented as a non-negative integer, -2 is returned. SyntaxParameterThe above method requires only one parameter: The codePoint is the character(Unicode code point) to be converted. Return ValueThe getNumericValue(int codePoint) method returns the numeric value of the character, as a non-negative int value. This method will return -2 if the character has a numeric value but the value cannot be represented as a non-negative int value. The method will return -1 if the character has no numeric value.. Example 1Test it NowOutput: The character 'n' has a numeric value represented as: 23 Example 2Test it NowOutput: Numeric value for code point obj1 is 33 Numeric value for code point obj2 is -1 Example 3Test it NowOutput: The character 'n' has a numeric value represented as: 23 The character ' ' has a numeric value represented as: -1 The character '6' has a numeric value represented as: 6
Next TopicJava Character
|