给定一个正整数,返回它在 Excel 表中相对应的列名称。
例如,
1 -> A
2 -> B
3 -> C
...
26 -> Z
27 -> AA
28 -> AB
...
示例 1:
输入: 1
输出: "A"
示例 2:
输入: 28
输出: "AB"
==============================================================================================
可以看成是求一个数的26进制,但是不是逢26进1,26的时候是Z,所以在求余时就要注意
public static void main(String[] args) {
int n = 701;
System.out.println(convertToTitle(n));
}
public static String convertToTitle(int n) {
String str = "";
while(n > 0){
char s = (char)((n - 1)%26 + 'A');
str = s + str;
n = (n - 1)/26;
}
return str;
}