Skip to main content
๐Ÿ“œ WAYPOINT LESSON

Character classification and shifts

โญโญโญ advancedโณ 10 min read๐Ÿ“ Lesson 178 of 256

Raw classification without imports, char arithmetic with wrap-around, and the pass-through rule for non-letters.

Character classification without imports. The exam gives you Character.isLetter/isDigit/isUpperCase โ€” and a raw alternative:

char ch = s.charAt(i);
boolean letter = (ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z');
boolean digit  = ch >= '0' && ch <= '9';

char arithmetic (Caesar shifts, digit sums):

char shifted = (char) ('a' + (ch - 'a' + k) % 26);   // wrap letters
int digitVal = ch - '0';                              // '7' -> 7

The two classic boundary questions: does k = 26 (or a multiple) wrap back exactly (yes โ€” % 26 handles it), and does the digit formula work for '0' (yes โ€” 0). Non-letters pass through unchanged in a shift; forgetting the pass-through breaks half the hidden tests.

Scanning words in a string with arbitrary spaces: a boolean "inside a word" state, flipped at transitions โ€” not a split (the AP subset has no split).