十进制转换为任意进制

思路:定义一个整数,除以所要换的进制,循环除,保存余数到一个数组,输出

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]);
		}
	}

}

猜你喜欢

转载自1943068620.iteye.com/blog/2376550