진법 변환

Day8 8단계 20231026

1. 2745번 진법 변환

  1. 10진법을 n진법으로 변환 : 10진법으로 나타낸 수를 n으로 나누어 그 나머지 값을 다시 n으로 나누는 것을 반복해서 더 이상 나눌 수 없을 때까지 반복. 그 후 각 나누기 단계에서 나온 나머지 값을 순서대로 읽는다.
  2. n진법을 10 진법으로 변환 : 10진법 자리수 * n진법의 i제곱(i는 인덱스)
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		String str = st.nextToken();
		int b = Integer.parseInt(st.nextToken());
		int conv = Integer.parseInt(str, b);
		System.out.println(conv);	
	}
}