Converting Unicode Characters to Digits - Java Language Basics

Java examples for Language Basics:char

Description

Converting Unicode Characters to Digits

Demo Code

public class Main {

  public static void main(String[] args) {

    int x = 0;/*w  w  w.  j  a va2s  .com*/
    for (int c = 0; c <= 0x10FFFF; c++) {
      if (Character.isDigit(c)) {
        ++x;
        System.out.printf(
            "Codepoint: 0x%04X\tCharacter: %c\tDigit: %d\tName: %s\n", c, c,
            Character.digit(c, 10), Character.getName(c));
      }
      if(x == 10){
        break;
      }
    }
    System.out.printf("Total digits: %d\n", x);
  }
}

Related Tutorials