Check If Value Is ASCII 7-Bit Control Character in Java



To check whether the entered value is ASCII 7-bit control character, check the characters ASCII value before 32 and 127. These are the control characters.

Here, we have a character.

char one = ' n ';

Now, we have checked a condition with if-else to check for character less than 32 (ASCII) and equal to 127.

if (one < 32 || one == 127) {
System.out.println("Given value is a control character!");
} else {
   System.out.println("Given value is not a control character!");
}

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char one = '\n';
      if (one < 32 || one == 127) {
         System.out.println("Given value is a control character!");
      } else {
         System.out.println("Given value is not a control character!");
      }
   }
}

Output

Given value is a control character!
Updated on: 2020-06-26T07:13:37+05:30

267 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements