Java Program to check whether the character is ASCII 7 bit printable

Java 8Object Oriented ProgrammingProgramming

To check whether the entered value is ASCII 7-bit printable, check whether the characters ASCII value is greater than equal to 32 and less than 127 or not. These are the control characters.

Here, we have a character.

char one = '^';

Now, we have checked a condition with if-else for printable characters.

if (c >= 32 && c < 127) {
   System.out.println("Given value is printable!");
} else {
   System.out.println("Given value is not printable!");
}

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char c = '^';
      System.out.println("Given value = "+c);
      if (c >= 32 && c < 127) {
         System.out.println("Given value is printable!");
      } else {
         System.out.println("Given value is not printable!");
      }
   }
}

Output

Given value = ^
Given value is printable!

Let us see another example wherein the given value is a character.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char c = 'y';
      System.out.println("Given value = "+c);
      if ( c >= 32 && c < 127) {
         System.out.println("Given value is printable!");
      } else {
         System.out.println("Given value is not printable!");
      }
   }
}

Output

Given value = y
Given value is printable!
raja
Published on 07-Dec-2018 11:11:52
Advertisements