public class PrintExcelColumnName {
public static void main(String args[]) {
printColumnName(20000);
}
static void printColumnName(int num){
StringBuilder sb = new StringBuilder();
while(num>26) {
int diff = num%26;
num = num/26;
sb.append((char)(diff-1+'A'));
}
sb.append((char)(num-1+'A'));
System.out.println(sb.reverse().toString());
}
}
output: ACOF
public static void main(String args[]) {
printColumnName(20000);
}
static void printColumnName(int num){
StringBuilder sb = new StringBuilder();
while(num>26) {
int diff = num%26;
num = num/26;
sb.append((char)(diff-1+'A'));
}
sb.append((char)(num-1+'A'));
System.out.println(sb.reverse().toString());
}
}
output: ACOF
No comments:
Post a Comment