Java Program to check whether the character is ASCII 7 bit

Java 8Object Oriented ProgrammingProgramming

To check whether the character is ASCII 7 bit or not, check whether given value’s ASCII value is less than 128 or not.

Here, we have a character.

char one = '-';

Now, we have checked a condition with if-else for ASCII 7-bit character.

if (c < 128) {
System.out.println("Given value is ASCII 7 bit!");
} else {
   System.out.println("Given value is not an ASCII 7 bit!");
}

The following is an example wherein we check a character for ASCII 7-bit.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char c = '-';
      System.out.println("Given value = "+c);
      if ( c < 128) {
         System.out.println("Given value is ASCII 7 bit!");
      } else {
         System.out.println("Given value is not an ASCII 7 bit!");
      }
   }
}

Output

Given value = *
Given value is ASCII 7 bit!

Let us see an example wherein we have a character and check whether the entered value is ASCII 7-bit or not.

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char c = 'u';
      System.out.println("Given value = "+c);
      if ( c < 128) {
         System.out.println("Given value is ASCII 7 bit!");
      } else {
         System.out.println("Given value is not an ASCII 7 bit!");
      }
   }
}

Output

Given value = u
Given value is ASCII 7 bit!
raja
Published on 10-Dec-2018 12:13:33
Advertisements