- 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
isLetterOrDigit() method in Java
The isLetterOrDigit() method in Java returns TRUE if the entered value is a letter or digit.
We have the following character.
char val ='P';
Now, let us check for letter or digit using if-else decision-making statement.
if (Character.isLetterOrDigit(val)) { System.out.println("Value is a letter or digit!"); } else { System.out.println("Value is neither a letter nor a digit!"); }
The following is an example.
Example
public class Demo { public static void main(String []args) { char val ='P'; System.out.println("Value: "+val); if (Character.isLetterOrDigit(val)) { System.out.println("Value is a letter or digit!"); } else { System.out.println("Value is neither a letter nor a digit!"); } } }
Output
Value: P Value is a letter or digit!
Let us see another example.
Example
public class Demo { public static void main(String []args) { char val ='^'; System.out.println("Value: "+val); if (Character.isLetterOrDigit(val)) { System.out.println("Value is a letter or digit!"); }else { System.out.println("Value is neither a letter nor a digit!"); } } }
Output
Value: ^ Value is neither a letter nor a digit!
Advertisements