用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 }

 

转载于:https://www.cnblogs.com/zanzan101/p/3365441.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值