Java Program to check input is Digit or Alphabets or Special Character

Java Program to check input is Digit or Alphabets or Special Character

In this tutorial you will be learning Writing Java Program to check a Given input is either a Digit or an Alphabet or a Symbol.

For Example:

Example 1:

Suppose a given input is 10

Then the output should be “Given input is a digit”.

Example 2:

And for the input A or any character

The output should be “Given input is an Alphabet”.

Example 3:

And for the input “#” or any other Special Character.

The output should be “Given input is a Special Character”.

Program to check input is Digit or Alphabet or Character in Java

import java.util.*;
public class Main
{
  public static void main (String[] args)
  {
    System.out.println("Check if input is Digit/Alphabet/Special Character");
    Scanner sc = new Scanner (System.in);
    System.out.println ("Enter a input");
    char ch = sc.next ().charAt (0);
     if (Character.isLetter(ch)) {
         System.out.println("Given input is an Alphabet.");
     }else if(ch>='0' && ch<='9')
	 {
	  	System.out.println("Given Input is Digit.");
	 } else{
	     System.out.println("Given Input is Special Character.");
	 } 
  }
}

Output 1:

Check if input is Digit/Alphabet/Special Character
Enter a input
34
Given Input is Digit.

Output 2:

Check if input is Digit/Alphabet/Special Character
Enter a input
ww
Given input is an Alphabet.

Output 3:

Check if input is Digit/Alphabet/Special Character
Enter a input
#$
Given Input is Special Character.