用JAVA写的一个十进制转换任意进制数的程序

 1 import java.io.*;
 2 
 3 public class TEST1 {
 4     public static void main(String args[]) throws IOException
 5     {
 6         int count = 0;
 7         byte buff[] = new byte[1024];
 8         count = System.in.read(buff);
 9         String strings = new String(buff, 0, count);
10         String string[] = strings.split(",");
11         int num = Integer.parseInt(string[0].trim());
12         int m = Integer.parseInt(string[1].trim());
13 
14         int arr[] = new int[1024];
15 
16 
17         //System.out.println(num);
18         //System.out.println(m);
19 
20         count = 1023;
21         while(num > 0)
22         {
23             arr[count] = num%m;
24         //    System.out.println(arr[count]);
25             count--;
26             num = num/m;
27         }
28         for(;count < 1023; count++)
29             if(arr[count+1] < 10)
30                 System.out.print(arr[count+1]);
31             else
32             {
33                 char ch = (char)(arr[count+1]-10+65);
34                 System.out.print(ch);
35             }
36     }
37 }

 

posted @ 2013-10-12 16:06  铁甲小宝  阅读(373)  评论(0编辑  收藏  举报