Java Character.digit(char ch, int radix)

Syntax

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

public static int digit(char ch, int radix)

Example

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


public class Main {
/*w w w. j  a va2 s. co m*/
   public static void main(String[] args) {
      char ch1 = '9';
      char ch2 = '3';

      int i1 = Character.digit(ch1, 2);
      int i2 = Character.digit(ch2, 10);

      System.out.println("Numeric value of " + ch1 + " in radix 2 is " + i1);
      System.out.println("Numeric value of " + ch2 + " in radix 10 is " + i2);

   }
}

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