Character is Uppercase, Lowercase, Digit or Special character using Java

Character is Uppercase, Lowercase, Digit or Special Character using java :

 

Characters may be an Alphabet ( Uppercase or Lowercase ), Digit or a Special character. All the characters are associated with a number known as ASCII ( American Standard Code for Information Interchange ) value. ASCII values of characters are mentioned below : –

Uppercase letters : – A to Z ( 65 to 90 )

Lowercase letters : – a to z ( 97 to 122 )

Digits : – 0 to 9 ( 48 to 57 )

Except above ASCII values all other values between the range 0 to 127 are associated with special characters. Special characters may involve @, !, $, #, %, &, <, ?, etc.

So, now we create a java program to check the character is in uppercase letter or in lowercase letter or a digit or a special character.

Working :

Step 1 : Ask the user to enter a character.

Step 2 : Use first condition to check whether the character entered by the user is in uppercase letter or not.

Step 3 : Use second condition to check whether the character entered by the user is in  lowercase letter or not.

Step 4 : Use third condition to check whether  the character entered by the user is digit or not.

Step 5 : Use last condition i.e. else condition for the special characters because remaining others will be the special characters.

Step 6 : Print the result.

Code in Java :

//character is uppercase, lowercase, digit or special character using java
import java.util.Scanner;
public class low_upp_dig_spcl
{
public static void main(String[] args)
{
//scanner class declaration
Scanner sc = new Scanner(System.in);
//input from the user
System.out.print("Enter a character : ");
char c = sc.next().charAt(0);
int n = c;
//condition for uppercase
if(c >=65 && c <=90)
System.out.println("Uppercase");
//condition for lowercase
else if(c >= 97 && c <=122 )
System.out.println("Lowercase");
//condition for digit
else if(c >=48 && c <= 57)
System.out.println("Digit");
//condition for special characters
else
System.out.println("Special Character");
System.out.println("ASCII value : "+n);
//closing scanner class(not compulsory, but good practice)
sc.close();
}
}

Output :

Enter a character : @

Special Character

ASCII value : 64


Enter a character : s

Lowercase

ASCII value : 115