본문 바로가기

Algorithm/Baekjoon

[백준_JAVA] 11005 진법 변환 2

import java.util.Scanner;

public class Main{
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
    	 	
    	int N = sc.nextInt();
        int B = sc.nextInt();
        String result = "";
        
        while(N > 0) {
            if(N%B >= 10)
            	result += (char)((N%B)-10+'A');
            else
            	result += (char)((N%B)+'0');
            	
            N=N/B;
        }
        
        for (int i = result.length() - 1; i >= 0; i--) {
            System.out.print(result.charAt(i));
        }
        sc.close();
    }
}