This article is in the study summary, welcome reprint but please specify Source:http://blog.csdn.net/pistolove/article/details/42554641
Given a positive integer, return its corresponding column title as appear in an Excel sheet.
For example:
1, A 2, B 3, C ... AA, Z
Ideas:
(1) Test instructions the string corresponding to the column in Excel, given any integer.
(2) The essence of this problem is to examine the application of "26-system". Because the problem is relatively simple, here is not verbose, see the code below.
(3) Hope this article is helpful to you.
The algorithm code is implemented as follows:
public static String converttotitle (int num) {if (num < 1) {return "";} else {String temp = ""; StringBuffer buffer = new StringBuffer (), while (num > 0) {num--;char c = (char) (num% + ' A '), temp + = C;num/= 26;} for (int i = Temp.length ()-1; I >= 0; i--) {Buffer.append (Temp.charat (i));} return buffer.tostring ();}}
Excel Sheet Column Title