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
Answered By
3 Likes
Related Questions
Write a program that inputs a number and tests if the given number is a multiple of both 3 and 5.
Write a program that inputs a character and prints if the typed character is in uppercase or lowercase.
Write a program that inputs an alphabet and checks if the given alphabet is a vowel or not.
Write a program that takes a number and check if the given number is a 3 digit number or not. (Use if to determine)