Home / Programs / Write a short program to find whether the given character is a digit or a letter.
🚀 Programming Example

Write a short program to find whether the given character is a digit or a letter.

👁 11 Views
💻 Practical Program
📘 Step Learning
Learn this program step-by-step with algorithm, source code, output and detailed explanation.

📌 Information & Algorithm

Given Input:

Enter a character: A

Expected Output:

It is a Letter.

Given Input:

Enter a character: 7


Expected Output:

It is a Digit.

💻 Program Code

import java.util.Scanner;

public class CheckCharacter {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        System.out.print("Enter a character: ");
        char ch = sc.next().charAt(0);

        if (Character.isDigit(ch)) {
            System.out.println("It is a Digit.");
        } 
        else if (Character.isLetter(ch)) {
            System.out.println("It is a Letter.");
        } 
        else {
            System.out.println("It is neither a Digit nor a Letter.");
        }

        sc.close();
    }
}

                        
📚 Learning Subject

Master Programming Through Practical Examples

Improve your coding logic, problem-solving skills and programming confidence by practicing real-world examples with explanations.

🎯 How to learn from this example

First understand the algorithm carefully. Then study the program line-by-line and compare it with the output. Finally, review the explanation section to strengthen your logic and programming understanding.

🔥 Practice suggestion

Rewrite the program without looking at the code. Modify values, conditions or logic and run it again. This helps improve confidence and strengthens coding skills much faster.