Java Character digit() MethodJava Character digit(char ch, int radix) MethodThe digit(char ch, int radix) method of character class returns the numeric value of the character. If the radix is not in the range MIN_RADIX<=radix<=MAX_RADIX or if the value of ch is not a valid digit in a particular radix, 1 is returned. A character is a valid digit if atleast one of the following is true.
Note: This method cannot handle the supplementary character.SyntaxParameterThe above method requires two parameters:
Return ValueThe digit(char ch, int radix) method returns the numeric value represented by the character in the specified radix. Example 1Output: Enter the input of your choice:4 Enter the radix:6 The numeric value of the character is returned as: 4 Example 2Output: The numeric value of 9 in radix 4 is:-1 The numeric value of 5 in radix 8 is:5 Example 3Output: The numerical value for the alphabets:'a', 'b', 'c', 'd' is given as -1 The numeric value of 5 in radix 4 is: 5 Java Character digit(int codePoint, int radix) MethodThe digit(int codePoint, int radix) method of character class returns the numeric value of the character. If the radix is not in the range MIN_RADIX<=radix<=MAX_RADIX or if the value of ch is not a valid digit in a particular radix, -1 is returned. A character is a valid digit if atleast one of the following is true.
SyntaxParameterThe above method requires two parameters:
Return ValueThe digit(int codePoint, int radix) method returns the numeric value represented by the character in the specified index. Example 4Output: The character has a numeric value as -1 using the radix 20 Example 5Output: The character has a numeric value as -1 using the radix 69 The character has a numeric value as -1 using the radix 18 Next TopicJava-character-equals-method |