Excel Sheet Column Title

Source: Internet
Author: User

Excel Sheet Column Title

Problem:

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

Ideas:

Inbound access issues

My Code:

 Public classSolution { PublicString Converttotitle (intN) {stringbuffer sb=NewStringBuffer (); if(n <= 0)returnsb.tostring ();  while(n! = 0) {sb.append (GetChar (n-1)%26)); N= (n-1)/26; }        returnsb.reverse (). toString (); }     Public CharGetChar (intnum) {        return(Char) (' A ' +num); }}
View Code

Others code:

 Public class Solution {    public String converttotitle (int  n) {         new  StringBuilder ();          while (n>0)        {            result.append ((char) ((n-1)%26 + (int) ' A ');             = (n-1)/26;        }         return result.reverse (). toString ();    }}
View Code

The Learning Place:

    • In Java, char is two bytes, int is four bytes, so char to int to use the cast, often forget this point, have several times warning.
    • usually with S + = part never wanted s = part + s So it can be easily implemented reverse, learning, concrete implementation in other people's code inside there.

Excel Sheet Column Title

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.