标签:
7 2 23 12 -4 3
111 1B -11
import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner sc = new Scanner(System.in); char chs[] = {'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; while(sc.hasNext()){ int n = sc.nextInt(); int r = sc.nextInt(); boolean isNegative = false; if(n<0){ n=-n; isNegative = true; } String str = ""; while(n/r>0){ str = chs[n%r]+str; n = n/r; } if(n%r!=0){ str = chs[n%r]+str; } if(isNegative){ str = "-" + str; } System.out.println(str); } } }
标签:
原文地址:http://blog.csdn.net/u011479875/article/details/45627803