Java Data Type Tutorial - Java Character.forDigit(int digit, int radix)








Syntax

Character.forDigit(int digit, int radix) has the following syntax.

public static char forDigit(int digit,  int radix)

Example

In the following code shows how to use Character.forDigit(int digit, int radix) method.

//www .j av a  2s .  co  m

public class Main {
   public static void main(String[] args) {
      int i1 = 5;
      int i2 = 14;

      char ch1 = Character.forDigit(i1, 10);
      char ch2 = Character.forDigit(i2, 16);

      String str1 = "Char representation of " + i1 + " in radix 10 is " + ch1;
      String str2 = "Char representation of " + i2 + " in radix 16 is " + ch2;

      System.out.println( str1 );
      System.out.println( str2 );
   }
}

The code above generates the following result.