Originally Posted by
aussiemcgr
2 reasons.
1) My values received start at 1, so it only seemed to make sense to also start at 1.
2) I couldnt figure out how to change the loop to tell it to stop since I'm using Integer Division and I would need to get a 0 value.
I just mention the zero index because things can get quite messy with higher values. Easier for me to write the code than explain a fix, so have a look at the following...if the parameter you have is 1 based and not zero based, just send the function n-1.
public String getLetter(int n)
{
String[] letters = new String[] {"A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"};
String ans = "";
while(n>-1)
{
ans = letters[n%26]+ans;
n = n/26 - 1;
}
return ans;
}