Find out whether the given input is letter or digit

 Program to find whether a given character is a digit or a letter


import java.util.Scanner; //Importing Scanner class to get input from the user

public class Identify
{
       
    public static void main(String []args) // Main method
    {
        char a;
        
        System.out.println("Enter digit or a letter"); //Instruction to User
        a = new Scanner(System.in).next().charAt(0);
        
        if((a>'a' && a<'z')||(a>'A' && a<'Z'))
        {
            System.out.println("This is a letter"); //If the given character is letter
        }
        else
        {
            System.out.println("This is a digit"); //If the given character is digit
        }
    }
    
}

Output of the above the program is:-

First execution(G as an input)
Output
Enter digit or a letter
G
This is a letter

Second execution(8 as an input)
Output
Enter digit or a letter
8
This is a digit


Comments

Popular posts from this blog

Java program using Scanner Class

Java Program to make a comparison between numbers

Calculate the area of Rectangle Using Constructor Overloading rules