











Java Program for finding whether a character is in Uppercase, Lowercase or is a special character.
Finding whether a Character is Uppercase, Lowercase or Special Character.
In this article, we’ll learn about, how to find out that the character that has been entered by the user is an Uppercase Letter, a Lowercase Letter or a Special Character. The above can be achieved by comparing the ASCII Code (American Standard Code for Information Exchange) of the corresponding input character. For example, ASCII Code for small letter starts from 97 for ‘a’ and ends at 122 for ‘z’. There’s a difference of 32.


Algorithm
- Take the input from the user.
- Use Conditional Statements (If-Else) to determine the range of the ASCII Code for the corresponding Input Character.
- Write print statements in the respective conditional blocks.
JAVA Program
import java.util.*; public class Main { public static void main(String[] args) { Scanner s= new Scanner(System.in); System.out.println("Enter a Character"); char c=s.next().charAt(0); if(48<=c && c<=57) //using ascii codes of digit where 0-48 and 9-57 System.out.println(" Digit"); else if(65<=c && c<=90) //using ascii codes of Uppercase letters where A-65 and Z-90 System.out.println("Uppercase Letter"); else if(97<=c && c<= 122) //using ascii codes of Lowercase letters where a-97 and z-122 System.out.println("Lowercase Letter"); else //Rest of the characters ie. special characters System.out.println("Special Character"); } }
Login/Signup to comment