码迷,mamicode.com
首页 > 其他好文 > 详细

Excel Sheet Column Title

时间:2015-01-13 17:38:14      阅读:112      评论:0      收藏:0      [点我收藏+]

标签:

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

标签:

原文地址:http://www.cnblogs.com/mrpod2g/p/4221803.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!