Java Character forDigit() MethodThe forDigit(int digit, int radix) method of character class determines the character representation for a specific digit in the specified radix. If the value of the digit is not a valid digit in the specified radix or if the value of the radix is not a valid radix then a null character is returned. If the digit is less than 10, the '0'+digit is returned. Otherwise, the value 'a'+digit-10 is returned. SyntaxParameterThe above method requires two parameters: The digit that needs to be converted to a character. The radix Return ValueThe forDigit(int digit, int radix) method returns the char representation of the specified digit in the specified index. Example 1Test it NowOutput: The char representation of 5 in radix 10 is 5 The char representation of 6 in radix 16 is 6 Example 2Test it NowOutput: The char representation of 5 in radix 10 is 5 The char representation of 15 in radix 16 is f The char representation of 27 in radix 16 is r Example 3Output: Enter an input:4 Enter the radix:7 The character representation using radix '7' for digit 4 is : 4
Next TopicJava Character
|