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


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)!

Samual Sam
Samual Sam

Learning faster. Every day.

Updated on: 25-Jun-2020

83 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements