[Java] BufferedReader를 이용한 여러줄 입력 기능

김선호·2022년 10월 10일
0

Java 문법

목록 보기
14/15
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {
    public static void main(String[] args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        List<String> strings = new ArrayList<>();

        try {
            String str;

            while (!(str = br.readLine()).equals("")) {
                strings.add(str);
            }
        } catch (IOException e) {
            throw new RuntimeException(e);
        }

        System.out.println(strings);
    }
}
profile
Every Run, Learn Counts.

0개의 댓글