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.


//from w  w w. j  a  va 2  s.com

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.





















Home »
  Java Tutorial »
    java.lang »




Boolean
Byte
Character
Class
Double
Enum
Float
Integer
Long
Math
Number
Object
Package
Process
ProcessBuilder
Runnable
Runtime
SecurityManager
Short
StackTraceElement
StrictMath
String
StringBuffer
StringBuilder
System
Thread
ThreadGroup
ThreadLocal
Throwable