题解 | #进制转换#
进制转换
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) { int num = M; if (num < 0) { num = Math.abs(M); } String table = "0123456789ABCDEF"; char[] chars = table.toCharArray(); StringBuilder sb = new StringBuilder(); while (num > 0) { int i = num % N; sb.append(chars[i]); num = num / N; } if (M < 0) { sb.append("-"); } return sb.reverse().toString(); } }#在找工作求抱抱#