Wednesday, 10 October 2018

PrintExcelColumnNameFromColumnNumber

public class PrintExcelColumnName {
    public static void main(String args[]) {
        printColumnName(20000);
    }
   
    static void printColumnName(int num){
        StringBuilder sb = new StringBuilder();
        while(num>26) {
            int diff = num%26;
            num = num/26;
            sb.append((char)(diff-1+'A'));
        }
        sb.append((char)(num-1+'A'));
       
        System.out.println(sb.reverse().toString());
    }
   
   
}

output: ACOF

No comments:

Post a Comment

links for Data Structure

  1) 𝐁𝐞𝐜𝐨𝐦𝐞 𝐌𝐚𝐬𝐭𝐞𝐫 𝐢𝐧 𝐋𝐢𝐧𝐤𝐞𝐝 𝐋𝐢𝐬𝐭:  https://lnkd.in/gXQux4zj 2) 𝐀𝐥𝐥 𝐭𝐲𝐩𝐞𝐬 𝐨𝐟 𝐓𝐫𝐞𝐞 𝐓𝐫𝐚𝐯𝐞𝐫𝐬𝐚𝐥𝐬...