Java Program to check whether the entered value is ASCII 7-bit control character

Java 8Object Oriented ProgrammingProgramming

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!
raja
Published on 10-Dec-2018 12:07:43
Advertisements