Printing ASCII values of characters
The code snippet below displays the ASCII value of each character of a String.
Code:
String str = "Java practice session. ";
for (int i=0; i<str.length();i++)
System.out.println(str.charAt(i) + " as ASCII value of: " + (int)str.charAt(i) );
Output:
Code:
J as ASCII value of: 74
a as ASCII value of: 97
v as ASCII value of: 118
a as ASCII value of: 97
as ASCII value of: 32
p as ASCII value of: 112
r as ASCII value of: 114
a as ASCII value of: 97
c as ASCII value of: 99
t as ASCII value of: 116
i as ASCII value of: 105
c as ASCII value of: 99
e as ASCII value of: 101
as ASCII value of: 32
s as ASCII value of: 115
e as ASCII value of: 101
s as ASCII value of: 115
s as ASCII value of: 115
i as ASCII value of: 105
o as ASCII value of: 111
n as ASCII value of: 110
. as ASCII value of: 46
as ASCII value of: 32