Thursday 26 March 2020

FINDING LETTERS, NUMBERS AND SPECIAL CHARACTERS USING JAVA LANGUAGE

Q-29- Any character is entered through the keyboard, write a java program to determine whether the character entered is a capital letter, a small case letter, a digit or a special symbol. The following table shows the range of ASCII values for various characters.  Characters ASCII Values 
A – Z 65 – 90 
a – z 97 – 122
0 – 9 48 – 57 
special symbols 0 - 47, 58 - 64, 91 - 96, 123 – 127

INPUT :
import java.util.Scanner;
public class NCM {

public static void main(String[] args) {
// TODO Auto-generated method stub
Scanner sc = new Scanner(System.in);
char ch;
System.out.println("Enter The Character :");
ch=sc.next().charAt(0);
if(ch>=65 && ch<=90)
{
System.out.println("This Character Is A Capital Letter. ");
}
else if(ch>=97 && ch<=122)
{
System.out.println("This Character Is A Small Letter. ");
}
else if(ch>=48 && ch<=57)
{
System.out.println("This Character Is A Digit.");
}
else if((ch>=0 && ch<=47) || (ch>=58 && ch<=64)
|| (ch>=91 && ch<=96) || (ch>=123 && ch<=127))
{
System.out.println("This Character Is A Special Symbol.");
}
else
{
System.out.println("You Have Entered Something Different.");
}

}


}

OUTPUT :
Enter The Character :
A

This Character Is A Capital Letter.

Enter The Character :
a
This Character Is A Small Letter.

Enter The Character :
5
This Character Is A Digit.

Enter The Character :
*
This Character Is A Special Symbol.


No comments:

Post a Comment