输入一个十进制数,输出对应的12进制
import java.util.*;
public class Main {
//12进制转换
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
String[] str = TenToTwelve(n);
for (int i = 0; i < str.length; i++) {
System.out.print(str[i]);
}
}
private static String[] TenToTwelve(int number) {
ArrayList<Integer> newnum = new ArrayList<Integer>();
int j = number % 12;
int i = number / 12;
newnum.add(j);
while (i != 0) {
j = i % 12;
i = i / 12;
newnum.add(j);
}
int length = newnum.size();
String[] out = new String[length];
for (int k = 0; k < length; k++) {
switch (newnum.get(length-k-1)) {
case 10:out[k]="A" ;break;
case 11:out[k]="B" ;break;
default: out[k]=newnum.get(length-k-1).toString();
}
}
return out;
}
}