user3571012 user3571012 - 2 months ago 8
Java Question

How to print an ASCII table?

I'm trying to print an ASCII table with each number and its corresponding value, but I don't know how to get the character associated with the number.

public static void main(String[] args) {

for(char letter= ' ';letter<274;letter++)
System.out.print(letter);
}


How can I print the associated character with the number?

Answer

It's simple ...

   for (int c=32; c<128; c++) {
    System.out.println(c + ": " + (char)c);
   } 
Comments