Java Program to check whether the entered character is ASCII 7 bit numeric and character

Java 8Object Oriented ProgrammingProgramming

To check whether the entered value is ASCII 7-bit numeric and character (alphanumeric), check the characters ASCII value for −

A to Z
Or
a to z
Or
0 to 9

Here, we have the following value −

char one = '5';

Now, we have checked some conditions with if-else for ASCII 7-bit numeric and character.

if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
System.out.println("Given value is numeric and character (alphanumeric)!");
} else {
System.out.println("Given value is not numeric and character!");
}

Example

 Live Demo

public class Demo {
public static void main(String []args) {
   char one = '5';
   if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
         System.out.println("Given value is numeric and character (alphanumeric)!");
      } else {
         System.out.println("Given value is not numeric and character!");
      }
   }
}

Output

Given value is numeric and character (alphanumeric)!

Let us see another example −

Example

 Live Demo

public class Demo {
public static void main(String []args) {
   char one = 'V';
   if ((one >= 'A' && one <= 'Z') || (one >= 'a' && one <= 'z') || (one >= '0' && one <= '9')) {
         System.out.println("Given value is numeric and character (alphanumeric)!");
      } else {
         System.out.println("Given value is not numeric and character!");
      }
   }
}

Output

Given value is numeric and character (alphanumeric)!
raja
Published on 07-Dec-2018 06:31:22
Advertisements