Java program to check whether a character is alphabet, digit or special character
/**
* Java program to check whether a character is alphabet, digit or special character
*/
import java.util.Scanner;
class Test
{
public static void main(String[] args)
{
char ch;
Scanner p=new Scanner(System.in);
System.out.print("Enter any char : ");
ch=p.next().charAt(0);
if((ch>='a'&&ch<='z')||(ch>='A'&&ch<='Z'))
{
System.out.println(ch+" is Alphabit");
}
else if(ch>='0'&&ch<='9')
{
System.out.println(ch+" is Digit");
}
else
{
System.out.println(ch+" is spacial Symble");
}
}
}
Output:
Enter any char : p
p is Alphabit
Enter any char : 8
8 is Digit
Enter any char : +
+ is spacial Symble