KnowledgeBoat Logo

Computer Applications

Write a program that inputs a character and prints if the user has typed a digit or an alphabet or a special character.

Java

Java Conditional Stmts

5 Likes

Answer

import java.util.Scanner;

public class KboatCheckLetterDigitSpChar
{
    public static void main(String args[]) {
        
        Scanner in = new Scanner(System.in);
        System.out.print("Enter a character: ");
        char ch = in.next().charAt(0);
        
        if(Character.isLetter(ch)) 
            System.out.println("Letter");       
        else if(Character.isDigit(ch)) 
            System.out.println("Digit");
        else if(!Character.isWhitespace(ch))
            System.out.println("Special character");
        
    }
}

Variable Description Table

Program Explanation

Output

BlueJ output of Write a program that inputs a character and prints if the user has typed a digit or an alphabet or a special character.BlueJ output of Write a program that inputs a character and prints if the user has typed a digit or an alphabet or a special character.BlueJ output of Write a program that inputs a character and prints if the user has typed a digit or an alphabet or a special character.

Answered By

3 Likes


Related Questions