Skip to content

Instantly share code, notes, and snippets.

@janakagamini
Last active March 14, 2019 07:37
Show Gist options
  • Save janakagamini/4d6262bb0219a32888c861d233afd548 to your computer and use it in GitHub Desktop.
Save janakagamini/4d6262bb0219a32888c861d233afd548 to your computer and use it in GitHub Desktop.
Integer to Alphabet Conversion
public class IntToAlphabet {
public static String toAlphabetic(int i) {
if (i < 0) {
return "-" + toAlphabetic(-i - 1);
}
int quot = i / 26;
int rem = i % 26;
char letter = (char) ((int) 'A' + rem);
if (quot == 0) {
return "" + letter;
} else {
return toAlphabetic(quot - 1) + letter;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment