题解 | #进制转换#
进制转换
https://www.nowcoder.com/practice/2cc32b88fff94d7e8fd458b8c7b25ec1
import java.util.*;
public class Solution {
/**
* 进制转换
* @param M int整型 给定整数
* @param N int整型 转换到的进制
* @return string字符串
*/
public String solve (int M, int N) {
// write code here
String str="0123456789ABCDEF";
String res="";
if(M==0) return "0";
boolean neg=false;
if(M<0){
M=-M;
neg=true;
}
while(M>0){
res=str.charAt(M%N)+res;
M/=N;
}
return neg?"-"+res:res;
}
}

