Lesson 24 of 34
Characters and ASCII
9 min 30 XP
Every char has a number (its ASCII/Unicode code): 'A' = 65, 'a' = 97, '0' = 48. So you can do maths with chars: 'a' + 1 is 'b'.
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.Count letter frequencies with an int array of size 26: count[ch - 'a']++. This trick solves anagram and first-non-repeating-character questions.
Example: edit me and press Run
Output Loading Java (first time takes a few seconds)
Press Run to see the result here.