We will write a program to determine entered character is a capital letter, small case letter, digit, or special symbol.
So First we should take character input from user. Now the character in variable c.Take another variable ascii and make ascii=c.ascii variable stores
ascii value of character.
Now we know that A-Z has ascii values 65-90, a-z has ascii values 97-122, 0-9 has ascii values 48-57, special symbols have ascii values 0-47,58-64,
91-96,123-127.
According to this we should insert the conditions in if else statements.
import java.util.Scanner; public class HelloWorld { public static void main(String[] args) { Scanner s=new Scanner(System.in); char c; int ascii; c=s.next().charAt(0); ascii=c; if(ascii>64 && ascii <91) System.out.println("Capital letter"); else if(ascii>96 && ascii <123) System.out.println("small letter"); else if(ascii>47 && ascii <58) System.out.println("Digits"); else if((ascii >=0 && ascii<=47)||(ascii >=58 && ascii<=64)||(ascii >=91 && ascii<=96)||(ascii >=123 && ascii<=127)) System.out.println("Special Symbols"); } }
1) G
Capital letter
2) s
small letter
3) 96
Digits
4) ( )space
special symbol
Submitted by Ginna Srilekha (ginnasrilekha)
Download packets of source code on Coders Packet
Comments