In Java, convert a number from 1 to 26 to a letter with (char) ('A' + n - 1). A char is a 16-bit number, so 'A' (65) plus 2 is 67, and the cast turns 67 into 'C'. Use 'a' instead of 'A' for lowercase. For spreadsheet columns, where 28 is "AB," build the string with (n - 1) % 26 in a loop.
Type numbers into the tool to get the letters and a complete Java class you can run with java NumToLetter.java. The char arithmetic panel shows each step: the code of 'A', the offset, the resulting int and its bits, and the char it casts to.
How number to letter Java calculator works?
To convert a number to a letter in Java, the number to letter Java calculator adds 64 to the number and reads the character with that code. The calculator splits your list of numbers, checks each one, converts 1–26 with (char) ('A' + n − 1), or builds column letters (27 = AA) in column mode, and writes runnable Java code for the same numbers. 8 5 12 12 15 becomes HELLO.
- Read the numbers
Spaces, commas, or new lines separate the numbers.
8 5 12 12 15 - Pick the mode
A1Z26 maps 1–26 to A–Z. Column mode maps any positive number to Excel column letters.
A1Z26 - Run (char) ('A' + n − 1)
Each number n becomes the character with code 64 + n (A = 65 in ASCII and Unicode).
(char) ('A' + 7) = 'H' - Write the code
The Java snippet and its output appear side by side. Tick lowercase to use code 96 + n.
HELLO
Column mode inserts (char) ('A' + r) at the front of a StringBuilder while n > 0, with r = (n − 1) % 26 and n = (n − 1) / 26. The (char) cast matters: without the cast, Java prints the int 72 instead of H.
Number to letter Java formula
The number to letter Java formula is a code point offset. letter = character(64 + n) for capitals and character(96 + n) for lowercase, for n from 1 to 26. Column letters use bijective base 26: take (n − 1) mod 26, then divide (n − 1) by 26, and repeat.
Formula
Where
- n
- number from 1 to 26 (A1Z26) or any positive whole number (columns)
- 64
- ASCII code of @, the character before A (65)
- 96
- ASCII code of `, the character before a (97)
- r
- remainder 0–25, read as A–Z
Worked example
Number to letter Java conversion chart
The number to letter Java conversion chart lists all 26 A1Z26 numbers with the ASCII codes and the Java expression. 1 = A (code 65), 13 = M (code 77), and 26 = Z (code 90).
| n | Letter | Code (capital) | Code (lowercase) | Java expression |
|---|---|---|---|---|
| 1 | A | 65 | 97 | (char) ('A' + 0) → 'A' |
| 2 | B | 66 | 98 | (char) ('A' + 1) → 'B' |
| 3 | C | 67 | 99 | (char) ('A' + 2) → 'C' |
| 4 | D | 68 | 100 | (char) ('A' + 3) → 'D' |
| 5 | E | 69 | 101 | (char) ('A' + 4) → 'E' |
| 6 | F | 70 | 102 | (char) ('A' + 5) → 'F' |
| 7 | G | 71 | 103 | (char) ('A' + 6) → 'G' |
| 8 | H | 72 | 104 | (char) ('A' + 7) → 'H' |
| 9 | I | 73 | 105 | (char) ('A' + 8) → 'I' |
| 10 | J | 74 | 106 | (char) ('A' + 9) → 'J' |
| 11 | K | 75 | 107 | (char) ('A' + 10) → 'K' |
| 12 | L | 76 | 108 | (char) ('A' + 11) → 'L' |
| 13 | M | 77 | 109 | (char) ('A' + 12) → 'M' |
| 14 | N | 78 | 110 | (char) ('A' + 13) → 'N' |
| 15 | O | 79 | 111 | (char) ('A' + 14) → 'O' |
| 16 | P | 80 | 112 | (char) ('A' + 15) → 'P' |
| 17 | Q | 81 | 113 | (char) ('A' + 16) → 'Q' |
| 18 | R | 82 | 114 | (char) ('A' + 17) → 'R' |
| 19 | S | 83 | 115 | (char) ('A' + 18) → 'S' |
| 20 | T | 84 | 116 | (char) ('A' + 19) → 'T' |
| 21 | U | 85 | 117 | (char) ('A' + 20) → 'U' |
| 22 | V | 86 | 118 | (char) ('A' + 21) → 'V' |
| 23 | W | 87 | 119 | (char) ('A' + 22) → 'W' |
| 24 | X | 88 | 120 | (char) ('A' + 23) → 'X' |
| 25 | Y | 89 | 121 | (char) ('A' + 24) → 'Y' |
| 26 | Z | 90 | 122 | (char) ('A' + 25) → 'Z' |
Column numbers past 26
| n | Column letters |
|---|---|
| 27 | AA |
| 28 | AB |
| 52 | AZ |
| 53 | BA |
| 78 | BZ |
| 702 | ZZ |
| 703 | AAA |
| 1,000 | ALL |
| 16,384 | XFD |
Java number to letter examples
char c = (char) ('A' + 5 - 1); // 'E'
String s = String.valueOf((char) (64 + 5)); // "E"
char lower = (char) ('a' + 5 - 1); // 'e'
// letter to number
int n = Character.toUpperCase('e') - 'A' + 1; // 5
// whole message
int[] nums = {8, 5, 12, 12, 15};
StringBuilder sb = new StringBuilder();
for (int x : nums) sb.append((char) ('A' + x - 1));
System.out.println(sb); // HELLO
Without the cast, 'A' + 4 is an int (69), and printing it shows "69," not "E." Java promotes char to int in arithmetic, so cast the result back to char.
Column letters in Java
static String toColumn(int n) {
StringBuilder sb = new StringBuilder();
while (n > 0) {
int r = (n - 1) % 26;
sb.insert(0, (char) ('A' + r));
n = (n - 1) / 26;
}
return sb.toString();
}
// toColumn(28) = "AB", toColumn(16384) = "XFD"
Apache POI has the same helper: CellReference.convertNumToColString(27) returns "AB," because POI counts columns from 0.
Frequently asked questions
How do I convert an int to a letter in Java?
Use (char) ('A' + n - 1) for n from 1 to 26, or (char) ('A' + n) if n starts at 0.
Why does Java print a number instead of a letter?
'A' + n is an int. Cast it with (char) before printing.
How do I convert a char to its alphabet position in Java?
Use Character.toUpperCase(c) - 'A' + 1. 'C' returns 3.
How do I get an Excel column letter in Java?
Use the loop on this page or Apache POI CellReference.convertNumToColString(index), which is 0-based.
What is the Java formula for number to letter?
The Java formula is (char) ('A' + n − 1), so n = 3 gives 'C'. Use 'a' in place of 'A' for lowercase.
What is (char) 65 in Java?
(char) 65 is 'A'. (char) 90 is 'Z' and (char) 97 is 'a'.
How do I convert an int array to letters in Java?
Loop over the array and append (char) ('A' + x − 1) to a StringBuilder. {3, 1, 20} builds "CAT".
More number and letter tools