코린이의 소소한 공부노트

[프로그래머스/Lv.0] 덧셈식 출력하기 본문

코딩테스트 풀이/JAVA

[프로그래머스/Lv.0] 덧셈식 출력하기

무지맘 2023. 4. 24. 22:55

1. Input, Output, Example

- 두 정수 a, b가 주어질 때 다음과 같은 형태의 계산식을 출력하는 코드를 작성

 

2. Constraint

1) 1 a, b 100

 

3. Code

1) 첫 코드(2023/04/24)

import java.util.Scanner;

public class Solution {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        System.out.println(a +" + "+ b + " = " + (a+b));
    }
}

2) 비교를 위해 작성한 코드(2023/04/24)

import java.util.*;
import java.io.*;
public class Solution {
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
        StringTokenizer token = new StringTokenizer(br.readLine());
        int a = Integer.valueOf(token.nextToken()), b = Integer.valueOf(token.nextToken());
        bw.write(a+" + "+b+" = "+(a+b));
        bw.flush(); bw.close();
    }
}

- 2번이 더 빠르다.