根据题意编写代码如下:
import java.util.Scanner;
public class Main {
public static void main(String []args){
int n, r;
String number = "";
boolean flag = true;
Scanner in = new Scanner(System.in);
while (in.hasNext()){
number = "";
flag = true;
n = in.nextInt();
r = in.nextInt();
if (n < 0){
flag = false;
n = -n;
}
while (n!=0){
int f = n%r;
if (f >= 10){
number+= (char)(f-10+'A');
}else{
number+= (char)(f+'0');
}
n/=r;
}
StringBuffer sb = new StringBuffer(number);
sb = sb.reverse();
if (!flag)System.out.print("-");
System.out.println(sb.toString());
}
}
}