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!"); }
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!"); } } }
Given value is a control character!