import java.util.*;
public class Demo1 {
public static void main(String args[]) {
Scanner sc = new Scanner(System.in);
System.out.println("请输入需要转换的数字:");
int X = sc.nextInt();
System.out.println("请输入需要转换成的进制:");
int Y = sc.nextInt();
int c = 0;
List l = new ArrayList();
System.out.print(X + "转换成" + Y + "进制是:\t");
for (; ; ) {
if (X < Y) {
l.add(X);
break;
}
l.add(X % Y);
X = X / Y;
}
Iterator<Integer> it = l.iterator();
int a[] = new int[l.size()];
while (it.hasNext()) {
a[c] = (int) it.next();
c++;
}
for (int i = 0; i < a.length; i++) {
System.out.print(a[l.size() - i - 1] + "");
}
}
}
JAVA进行进制转换,10进制转换为其他进制
最新推荐文章于 2023-05-16 13:17:53 发布