谢谢你 我做出来了 用集合
- import java.util.*;
- public class text {
- static ArrayList<Character> ary=new ArrayList();
- static ArrayList<Character> abit = new ArrayList();
- public static void main(String[]args){
- //
- char[] bit ="0123456789ABCDEF".toCharArray();
- Tianjia(abit,bit);
- Tianjia(ary,"".toCharArray());System.out.println(ary.size());
- int old,base;
- Scanner in=new Scanner(System.in);
- System.out.println("输入十进制数:");
- old=new Integer(in.next().trim());
- System.out.println("要转换的制数:");
- base=new Integer(in.next().trim());
- fun(ary,old,base);
- System.out.println(ary);
-
- }
- static void fun(ArrayList <Character>ary ,int n,int b){
- int len;
- if (n==0){
- copy(ary,0 ," ",0 );
- return ;
- }
- fun(ary,n/b,b);
- len=ary.size();
- ary.add(abit.get(n%b));
- }
- static void Tianjia(ArrayList<Character> J,char a[]){
- for(char c:a){
- J.add(c);
- }
- System.out.println(J);
- }
- static void copy(ArrayList a,int begin1,String s,int begin2){
- char ch[]=new String (s.toCharArray(),begin2,s.length()-1).toCharArray();
- for(int i:ch){
- a.set(i,ch[i]);
- }
- }
- }
复制代码
- [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F]
- []
- 0
- 输入十进制数:
- 121
- 要转换的制数:
- 2
- 复[]
- [1, 1, 1, 1, 0, 0, 1]
复制代码
|