|
发表于 2020-6-20 21:30:01
|
显示全部楼层
import java.util.Scanner;
public class Test34 {
public static void Cal(long max) {
String str34[] = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9",
"A", "B", "C", "D", "E", "F", "G", "H", "J", "K", "L", "M",
"N", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
String result = "";
String tmpStr = "";
long tmpI;
int maxWS = 1;
int tmpWS;
tmpI = max;
// 首先判断输入数字的34进制位数
while (tmpI / 34 > 34) {
maxWS++;
tmpI = tmpI / 34;
}
// 输出递增
for (int i = 0; i < max; i++) {
tmpI = i;
tmpWS = maxWS;
result = "";
while (tmpWS > 0) {
tmpStr = str34[(int) Math.floor(tmpI
/ Math.pow(34, (double) tmpWS))];
result = result + tmpStr;
if (tmpStr != "0") {
tmpI = tmpI- (new Double(Math.floor(tmpI/ Math.pow(34, (double) tmpWS)))).longValue() * (new Double(Math.pow(34, (double) tmpWS))).longValue();
}
tmpWS--;
}
result = result + str34[(int) i % 34];
System.out.println(result);
}
}
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
while (true) {
long num = in.nextLong();
if (num == 0) {
System.exit(0);
}
Cal(num);
}
}
}
任意输入一个十进制数字,调用Cal()方法打印从1递增到该十进制数字的34进制数 |
|