您的位置首页百科问答

怎么计算十二进制

怎么计算十二进制

的有关信息介绍如下:

怎么计算十二进制

import java.util.*; class Jinzhi { 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 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] + ""); } } }