Check whether the given character is an alphabet or a numeric character or special characterInput Format:Enter a Character as inputOutput Format:Print the output as "NUMBER" or "ALPHABET" or "SPECIAL CHARACTER"Constraints:0 <= CHARACTER <= 2^7Sample Input 1:7Sample Output 1:NUMBERSample Input 2:aSample Output 2:ALPHABET
Question
Check whether the given character is an alphabet or a numeric character or special characterInput Format:Enter a Character as inputOutput Format:Print the output as "NUMBER" or "ALPHABET" or "SPECIAL CHARACTER"Constraints:0 <= CHARACTER <= 2^7Sample Input 1:7Sample Output 1:NUMBERSample Input 2:aSample Output 2:ALPHABET
Solution
To check whether the given character is an alphabet, numeric character, or special character, follow these steps:
- Read the input character.
- Check if the ASCII value of the character lies between 48 and 57 (inclusive). If it does, then it is a numeric character.
- Check if the ASCII value of the character lies between 65 and 90 (inclusive) or between 97 and 122 (inclusive). If it does, then it is an alphabet.
- If the character does not fall into any of the above ranges, it is a special character.
- Print "NUMBER" if the character is a numeric character.
- Print "ALPHABET" if the character is an alphabet.
- Print "SPECIAL CHARACTER" if the character is a special character.
Here is the code snippet in Python to implement the above steps:
# Step 1: Read the input character
character = input("Enter a character: ")
# Step 2: Check if it is a numeric character
if ord(character) >= 48 and ord(character) <= 57:
print("NUMBER")
# Step 3: Check if it is an alphabet
elif (ord(character) >= 65 and ord(character) <= 90) or (ord(character) >= 97 and ord(character) <= 122):
print("ALPHABET")
# Step 4: It is a special character
else:
print("SPECIAL CHARACTER")
Sample Input 1:
7
Sample Output 1:
NUMBER
Sample Input 2:
a
Sample Output 2:
ALPHABET
Similar Questions
Check whether the given character is a Vowel or ConsonantInput Format:Enter a Character as input Output Format:Print the output as "Vowel" or "Consonant" Constraints:0 <= letter <= 2^7Sample Input 1:tSample Output 1:Consonant
Check whether the given character is in upper case or lower case or noneInput Format:Enter a Character as inputOutput Format:Print the output as "UPPERCASE" or "LOWERCASE" or "NONE"Constraints:0 <= INPUT <= 2^7Sample Input 1:ZSample Output 1:UPPERCASESample Input 2:zSample Output 2:LOWERCASE
Write a program that accepts an input string from the user and prints the total number of alphabet characters (A-z) in the string to the output.
Given a positive integer denoting , do the following:If , print the lowercase English word corresponding to the number (e.g., one for , two for , etc.).If , print Greater than 9.Input FormatThe first line contains a single integer, .ConstraintsOutput FormatIf , then print the lowercase English word corresponding to the number (e.g., one for , two for , etc.); otherwise, print Greater than 9 instead.Sample Input5Sample OutputfiveSample Input #018Sample Output #01eightSample Input #0244Sample Output #02Greater than 9
The code snippet below takes a character as input and prints as "alphabet", "digit" or "special character" depending on character provided as input.Choose the apt option to do this. Scanner sc=new Scanner(System.in); char ch = sc.next().charAt(0); if( ) System.out.println(ch+" is an alphabet"); else if( ) System.out.println(ch+" is a digit"); else System.out.println(ch+" is a special character");
Upgrade your grade with Knowee
Get personalized homework help. Review tough concepts in more detail, or go deeper into your topic by exploring other relevant questions.