Java Program to check whether the entered value is ASCII 7 bit alphabetic

Java 8Object Oriented ProgrammingProgramming

To check whether the entered value is ASCII 7-bit alphabetic, check the character from ‘a’ to ‘z’ or ‘A’ to ‘Z’.

Here, we have a character.

char one = 'r';

Now, we have checked a condition with if-else to check for character from ‘a’ to ‘z’ or ‘A’ to ‘Z’.

if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z')) {
   System.out.println("Given value is an alphabet!");
} else {
   System.out.println("Given value is not an alphabet!");
}

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char one = 'r';
      System.out.println("Character: "+one);
      if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z')) {
         System.out.println("Given value is an alphabet!");
      } else {
         System.out.println("Given value is not an alphabet!");
      }
   }
}

Output

Character: r
Given value is an alphabet!

Let us see another example

Example

 Live Demo

public class Demo {
   public static void main(String []args) {
      char one = '1';
      System.out.println("Character: "+one);
      if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z')) {
         System.out.println("Given value is an alphabet!");
      } else {
         System.out.println("Given value is not an alphabet!");
      }
   }
}

Output

Character: 1
Given value is not an alphabet!
raja
Published on 10-Dec-2018 07:33:29
Advertisements