백준 Copier

KIMYEONGJUN·2025년 4월 23일
0
post-thumbnail

문제

내가 생각했을때 문제에서 원하는부분

The first line will contain a single integer n that indicates the number of numbers to follow, each on their own line.
The next n lines will each contain a single number.

For each of the n lines, print out the original number and a copy of the number, with one space of separation.

내가 이 문제를 보고 생각해본 부분

BufferedReader로 입력을 받고, BufferedWriter로 출력을 해준다.
각 숫자를 읽어와서 동일한 숫자를 한 줄에 두 번 출력한다.
마지막에 flush()를 호출하여 버퍼에 남은 내용을 출력한다.

코드로 구현

package baekjoon.baekjoon_27;

import java.io.*;

// 백준 26574번 문제
public class Main1000 {
    public static void main(String[] args) throws IOException {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));

        int n = Integer.parseInt(br.readLine());
        for(int i = 0; i < n; i++) {
            String number = br.readLine();
            bw.write(number + " " + number);
            bw.newLine();
        }

        bw.flush();
        bw.close();
        br.close();
    }
}

마무리

코드와 설명이 부족할수 있습니다. 코드를 보시고 문제가 있거나 코드 개선이 필요한 부분이 있다면 댓글로 말해주시면 감사한 마음으로 참고해 코드를 수정 하겠습니다.

profile
Junior backend developer

0개의 댓글