[백준 2745] 진법변환<Java>

sso_ojiin·2021년 2월 22일
0

백준

목록 보기
4/15
post-thumbnail
import java.util.Scanner;

public class 진법변환 {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String n = sc.next();
		int b = sc.nextInt();
		int len = n.length();
		int sum=0;
		int number=0;
		
		for(int i=0;i<len;i++) {
			if(n.charAt(i)>=65) number=n.charAt(i)-55;
			else number=n.charAt(i)-'0';
			int a= (int) Math.pow(b, len-i-1);
			sum += a*number;
		}
		
		System.out.println(sum);
		
	}
}
profile
SSAFY 5기

0개의 댓글

Powered by GraphCDN, the GraphQL CDN