十进制转换为任意进制
程序员文章站
2022-03-21 11:12:13
...
思路:定义一个整数,除以所要换的进制,循环除,保存余数到一个数组,输出
package jinzhi.jinzhi; public class test1 { public static void main(String[] args) { // TODO Auto-generated method stub test1 test=new test1(); test.trans(19,8); } private void trans(int num, int k) { // TODO Auto-generated method stub int remain; int[] re=new int[100]; int location=0; while(num!=0){ remain=num%k; num=num/k; re[location]=remain; location++; } show(re,location); } private void show(int[] re, int location) { // TODO Auto-generated method stub for(int i=location-1;i>=0;i--){ System.out.print(re[i]); } } }
上一篇: 小米手环6真的是小米手环的毕业款吗?小米手环6使用测评
下一篇: C++函数对象详解附带实例