Last active
March 14, 2019 07:37
-
-
Save janakagamini/4d6262bb0219a32888c861d233afd548 to your computer and use it in GitHub Desktop.
Integer to Alphabet Conversion
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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