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



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 = '
';       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!
karthikeya Boyini
karthikeya Boyini

I love programming (: That's all I know


Advertisements