코딩테스트/[JAVA] 백준

[백준 | 11718번] 그대로 출력하기

냠냠쿠 2023. 8. 16. 21:32
728x90

 

https://www.acmicpc.net/problem/11718

📝 나의풀이

import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		while(scanner.hasNextLine()) {
			String A = scanner.nextLine();
			System.out.println(A);
		}
	}
}
  • while (true) 의 형식으로 제출 해 보니 런타임에러(nosuchelement)가 발생했다.
    입력이 없는 경우에 생기는 오류라고 함.
  • 서치 해 보니 hasnext메서드가 있었다. 뭔가 있으면 가져오는 느낌인듯.
728x90