Java Program to display printable characters

Java 8Object Oriented ProgrammingProgramming

To display printable characters, you need to work with the ASCII values from 32 to 127.

With that, we are using the following, instead of System.out.println()

System.out.write();

The following displays all the printable characters.

for (int i = 32; i < 127; i++) {
System.out.write(i);

Let us see the complete example.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      System.out.println("Printable characters...");
      for (int i = 32; i < 127; i++) {
         System.out.write(i);
         if (i % 8 == 7)
         System.out.write('\n');
         else
         System.out.write('\t');
      }
      System.out.write('\n');
   }
}

Output

Printable characters...
!"#$%&'
()*+,-./
01234567
89:;<=>?
@ABCDEFG
HIJKLMNO
PQRSTUVW
XYZ[\]^_
`abcdefg
hijklmno
pqrstuvw
xyz{|}~
raja
Published on 13-Nov-2018 14:29:05
Advertisements