Write a program to accept a character. If it is a letter, then display the case
lower or upper case), otherwise check whether it is a digit or a special character
× no spam ×
Answers
Step-by-step explanation:
Given a character, the task is to check whether the given character is in upper case, lower case or non-alphabetic character
Examples:
Input: ch = 'A'
Output: A is an UpperCase character
Input: ch = 'a'
Output: a is an LowerCase character
Input: ch = '0'
Output: 0 is not an aplhabetic character
Recommended: Please try your approach on {IDE} first, before moving on to the solution.
Approach: The key to solve this problem lies in the ASCII value of a character. It is the most simple way to find out about a character. This problem is solved with the help of following detail:
I know two languages python and JAVA so for these two I am providing the code
For python
ch = input()
if(ord(ch) >= 65 and ord(ch) <= 90):
print(“Upper”)
elif(ord(ch) >= 97 and ord(ch) <= 122):
print(“Lower”)
elif(ord(ch) >= 48 and ord(ch) <= 57):
print(“Number”)
else:
print(“Symbol”)
For JAVA
import java.util.*;
public class Main
{
public static void main(String[] args)
{
char ch;
Scanner sc = new Scanner(System.in);
ch = sc.next().charAt(0);
if(ch >= 65 && ch <= 90)
System.out.print(“Upper”);
else if(ch >= 97 && ch <= 122)
System.out.print(“Lower”);
else if(ch >= 48 && ch <= 57)
System.out.print(“Number”);
else
System.out.print(“Symbol”);
}
}