2031进制转换

    xiaoxiao2021-03-26  14

    import java.util.Scanner; public class P2031 { public static void main(Stringargs[]){ Scanner scanner = newScanner(System.in); char[]a={'0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'}; while(scanner.hasNext()){ int n=scanner.nextInt(); int r=scanner.nextInt(); boolean isNegative=false; if(n<0){ n=-n; isNegative=true; } String str = ""; while(n>0){ str = a[n%r]+str; n=n/r; } if(isNegative) str = '-'+str; System.out.println(str); } } }
    转载请注明原文地址: https://ju.6miu.com/read-450401.html

    最新回复(0)