题目
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
//将十进制数M转化为N进制数
Scanner sc = new Scanner(System.in);
int m = sc.nextInt();
int n = sc.nextInt();
StringBuffer sb = new StringBuffer();//1
String s = "0123456789ABCDEF";//2
boolean f = false;//3
//考虑十进制数字M是否为0
if(m == 0) {
sb.append('0');
}else if(m<0) {
m = -m;
f = true;
}
while(m!=0) {
sb.append(s.charAt(m%n));
m/=n;
}
if(f) {
sb.append("-");
}
System.out.println(sb.reverse().toString());
}
}