Here you can find the source of intToLetter(int index)
Parameter | Description |
---|---|
index | integer index to convert |
public static String intToLetter(int index)
//package com.java2s; //License from project: Apache License public class Main { /** Shifting index for converting column characters indexes to column numerical indexes*/ private static final int ALPHABET_SHIFT_INDEX = (int) 'a' - 1; /**//from w w w .j a va 2 s . c o m * Returns the 0-indexed String index correlating to the given integer index * * @param index integer index to convert * @return the 0-indexed String index correlating to the given integer index */ public static String intToLetter(int index) { index += 1; String str = ""; int r = index % 26; do { str = iIntToLetter(r) + str; index /= 26; r = index % 26; } while (r != 0); return str; } /** * Internal conversion from int to letter * * @param letterIndex to convert to a letter * @return String containing the letter that was indexed */ private static String iIntToLetter(int letterIndex) { if (letterIndex == 0) { letterIndex += 26; } String str = "" + (char) (letterIndex + ALPHABET_SHIFT_INDEX); return str.toUpperCase(); } }