본문 바로가기

알고리즘/백준

[백준] 11005 - 진법 변환 2 (JAVA/ 자바)

반응형

11005번 문제

1. Scanner를 이용한 방법

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();

    System.out.println(Integer.toString(N, B).toUpperCase());

    sc.close();
    }
}
import java.util.Scanner;

public class Main{
public static void main(String[] args){

    Scanner sc = new Scanner(System.in);

    System.out.println(Integer.toString(sc.nextInt(), sc.nextInt()).toUpperCase());

    sc.close();
    }
}

 

2. BufferedReader를 이용한 방법

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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(), " ");

    int N = Integer.parseInt(st.nextToken());
    int B = Integer.parseInt(st.nextToken());

    System.out.println(Integer.toString(N, B).toUpperCase());

    br.close();
    }
}
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

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(), " ");

    System.out.println(Integer.toString(Integer.parseInt(st.nextToken()), 
                                        Integer.parseInt(st.nextToken())).toUpperCase());

    br.close();
    }
}

저번에 봤던 획기적인 코드를 이번에 사용해봤다.

반응형