首先,正如已经提到的几个答案一样,有26个字母,因此请使用基本的26个系统,而不是27个.
除此之外,将A打印为0,而不是@,因此将(char)(余数64)更改为(char)(余数65).您需要做的最后一件事是更改quotient =(int)Math.floor(quotient / 27);因为您要打印A,所以此比例尺将为0,因此从中减去1并在商小于0时停止循环.
public class HelloWorld{
public static void main(String []args){
int counter=59;
for(int x=0; x<=counter; x++)
{
int quotient, remainder;
String result="";
quotient=x;
while (quotient >= 0)
{
remainder = quotient % 26;
result = (char)(remainder + 65) + result;
quotient = (int)Math.floor(quotient/26) - 1;
}
System.out.print(result+ " ");
}
}
}
输出(请注意,在输出开始时也没有空格):
A B C D E F G H I J K L M N O P Q R S T U V W X Y Z AA AB AC AD AE AF AG AH AI AJ AK AL AM AN AO AP AQ AR AS AT AU AV AW AX AY AZ BA BB BC BD BE BF BG BH
附:正确缩进您的代码!