- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
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
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
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)!
Advertisements