首页 > 代码库 > Excel Sheet Column Title

Excel Sheet Column Title

Given a positive integer, return its corresponding column title as appear in an Excel sheet.

For example:

    1 -> A    2 -> B    3 -> C    ...    26 -> Z    27 -> AA    28 -> AB 

 1 public class Solution { 2     public String convertToTitle(int n) { 3         String result=""; 4         while(n!=0){ 5             String a=""; 6             int temp=n%26; 7             if(temp==0){ 8                 a=String.valueOf(‘Z‘); 9                 n=n-26;10             }11             else{12                 a=String.valueOf((char)(temp-1+‘A‘));13             }14             result=a+result;15             n=n/26;16                 17         }18         return result;19     }20 }

 

Excel Sheet Column Title