Dremendo Tag Line

Check character is uppercase, lowercase, digit or symbol in Java

if else if - Question 4

In this question, we will see how input a character and check if it is an uppercase alphabet or lowercase alphabet or digit or a special symbol in Java programming using the if else if statement. To know more about if else if statement click on the if else if statement lesson.

Q4) Write a program in Java to input a character and check if it is an uppercase alphabet or lowercase alphabet or digit or a special symbol.

Program

import java.util.Scanner;

public class Q4
{
    public static void main(String args[])
    {
        char c;
        Scanner sc=new Scanner(System.in);
        System.out.print("Enter a character ");
        c = sc.nextLine().charAt(0);
        if(c>='A' && c<='Z')
        {
            System.out.print("Uppercase alphabet");
        }
        else if(c>='a' && c<='z')
        {
            System.out.print("Lowercase alphabet");
        }
        else if(c>='0' && c<='9')
        {
            System.out.print("Digit");
        }
        else
        {
            System.out.print("Special symbol");
        }
    }
}

Output

Enter a character 8
Digit
video-poster