Java Program to Check a Character is Uppercase or Lowercase or Digit

In this java program user enter a character and using of this character to check that character is uppercase or lowercase or digit or other. In ASCII (American Standard Code for Information Interchange) value 65 - 90 define uppercase ( A - Z ) and 97 - 122 define lowercase ( a - z ) and 48 - 57 define digit ( 0 - 9 ). Using of that ASCII value easily check character is what . 

Alphabate ASCII value Alphabate ASCII value Digit ASCII value
A
65
a
97
0
48
B
66
b
98
1
49
C
67
c
99
2
50
D
68
d
100
3
51
E
69
e
101
4
52
F
70
f
102
5
53
G
71
g
103
6
54
H
72
h
104
7
55
I
73
i
105
8
56
J
74
j
106
9
57
K
75
k
107
L
76
l
108
M
77
m
109
N
78
n
110
O
79
o
111
P
80
p
112
Q
81
q
113
R
82
r
114
S
83
s
115
T
84
t
116
U
85
u
117
V
86
v
118
W
87
w
119
X
88
x
120
Y
89
y
121
Z
90
z
122

Java code :
import java.util.*; 
 class ranjan
 { 
  public static void main(String args[]) 
  { 
   char ch = ' '; 
   Scanner sc=new Scanner(System.in);
   System.out.print("Enter a character : "); 
   ch=sc.next().charAt(0); 
   if(ch>=65 && ch<=90)
   {
    System.out.println(ch+" is a Uppercase character"); 
   }
   else if(ch>=97 && ch<=122)
   {
    System.out.println(ch+" is a lowercase character"); 
   }
   else if(ch>=48 && ch<=57)
   {
    System.out.println(ch+" is  a digit"); 
   } 
   else
   {
    System.out.println(ch+" is a special character"); 
   }
  } 
 }

Output :

Enter a character : g
g is a lowercase character

Post a Comment

0 Comments