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
public String convertToTitle(int n) {
StringBuilder result = new StringBuilder();
while(n>0){
n--;
result.insert(0, (char)('A' + n % 26));
n /= 26;
}
return result.toString();
}
Excel列标题转换算法
本文介绍了一种将正整数转换为Excel工作表中对应列标题的方法,类似于十进制到26进制的转换。通过一个简洁的Java代码示例展示了如何实现这一功能。
972

被折叠的 条评论
为什么被折叠?



