✏️ 문제풀이/백준
[백준/Java] 11718번 :: 그대로 출력하기
bono-hye
2024. 4. 14. 02:12
🌱 Scanner 사용
import java.util.Scanner;
public class Main
{
public static void main(String[] args)
{
Scanner sc = new Scanner(System.in);
while(sc.hasNextLine())
{
String str = sc.nextLine();
System.out.println(str);
}
sc.close();
}
}
🌱 BufferedReader 사용
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class Main
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String word;
while((word = br.readLine()) != null)
{
System.out.println(word);
}
}
}
💡 정리
BufferedReader 사용할 때, br.readLine()이 while 조건에 들어가야 하는 것 신경쓰기!
String word = br.readLine() / while (word != null) 이렇게 썼다가 무한루프에 빠져버렸다,,,
아차차! 하고 수정하니까 정상 실행~!