how-to

Working with Char

How to convert int code to ASCII char - and back

If you have int code you can convert it into ASCII char by typecasting only. It works both ways:

/* -- convert int code to ascii char */

int iCode = 65; // 'A'
System.out.println( (char)iCode );

/* -- convert ASCII char to int code */

char ch = 'A';
System.out.println( (int)ch );

System.out.println();

/* -- write ten chars from ASCII(65) => 'A' */

for ( int i = 65; i < 75; i++ )
  System.out.println( (char)i );
The output will be:
A
65

A
B
C
D
E
F
G
H
I
J