How to get ascii value of char in Java?

Getting ASCII Value of a Character in Java

Introduction

In Java, characters are represented by Unicode code points, which are used to identify and manipulate characters in the programming language. The ASCII (American Standard Code for Information Interchange) character set is a subset of the Unicode character set, and it is commonly used to represent characters in Java. In this article, we will explore how to get the ASCII value of a character in Java.

Direct Answer to the Question

The direct answer to the question "How to get ASCII value of a character in Java?" is:

public class Main {
public static void main(String[] args) {
char c = 'A';
System.out.println("The ASCII value of 'A' is: " + Character.getNumericValue(c));
}
}

Explanation

In this example, we first declare a character variable c and assign it the value ‘A’. We then use the Character.getNumericValue() method to get the ASCII value of the character. This method returns the numeric value of the character, which is equivalent to its ASCII value.

Alternative Method

Alternatively, we can use the Character.toCodePoint() method to get the ASCII value of a character:

public class Main {
public static void main(String[] args) {
char c = 'A';
System.out.println("The ASCII value of 'A' is: " + Character.toCodePoint(c));
}
}

Table: ASCII Values of Characters

Character ASCII Value
A 65
B 66
C 67
D 68
E 69
F 70
G 71
H 72
I 73
J 74
K 75
L 76
M 77
N 78
O 79
P 80
Q 81
R 82
S 83
T 84
U 85
V 86
W 87
X 88
Y 89
Z 90
` 91
92
93
n 94
r 95
t 96
b 97
f 98
v 99
100
1 101
2 102
3 103
4 104
5 105
6 106
7 107
8 108
9 109
– 110
= 111
+ 112
113
{ 114
} 115
[ 116
] 117
() 118
^ 119
& 120
* 121
+ 122
, 123
. 124
, 125
, 126
, 127
, 128
, 129
, 130
, 131
, 132
, 133
, 134
, 135
, 136
, 137
, 138
, 139
, 140
, 141
, 142
, 143
, 144
, 145
, 146
, 147
, 148
, 149
, 150
, 151
, 152
, 153
, 154
, 155
, 156
, 157
, 158
, 159
, 160
, 161
, 162
, 163
, 164
, 165
, 166
, 167
, 168
, 169
, 170
, 171
, 172
, 173
, 174
, 175
, 176
, 177
, 178
, 179
, 180
, 181
, 182
, 183
, 184
, 185
, 186
, 187
, 188
, 189
, 190
, 191
, 192
, 193
, 194
, 195
, 196
, 197
, 198
, 199
, 200
, 201
, 202
, 203
, 204
, 205
, 206
, 207
, 208
, 209
, 210
, 211
, 212
, 213
, 214
, 215
, 216
, 217
, 218
, 219
, 220
, 221
, 222
, 223
, 224
, 225
, 226
, 227
, 228
, 229
, 230
, 231
, 232
, 233
, 234
, 235
, 236
, 237
, 238
, 239
, 240
, 241
, 242
, 243
, 244
, 245
, 246
, 247
, 248
, 249
, 250
, 251
, 252
, 253
, 254
, 255
, 256
, 257
, 258
, 259
, 260
, 261
, 262
, 263
, 264
, 265
, 266
, 267
, 268
, 269
, 270
, 271
, 272
, 273
, 274
, 275
, 276
, 277
, 278
, 279
, 280
, 281
, 282
, 283
, 284
, 285
, 286
, 287
, 288
, 289
, 290
, 291
, 292
, 293
, 294
, 295
, 296
, 297
, 298
, 299
, 300
, 301
, 302
, 303
, 304
, 305
, 306
, 307
, 308
, 309
, 310
, 311
, 312
, 313
, 314
,

Unlock the Future: Watch Our Essential Tech Videos!


Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top