1. for문의 반복 범위가 [0, 100) 까지로 총 100개를 반드시 입력받고 있습니다.
만약 입력이 3줄일 때, 이클립스에선 Ctrl+z로 강제 종료가 가능하나, 채점 서버에선 100줄이 다 들어올 때 까지 기다리고 있겠군요 :)
2. 다른 이유로 while(test[i]!=null) 에서 문제가 발생할 수도 있습니다.
100줄 미만이라면 괜찮으나, 만일 100줄이 다 들어온 경우 test[] 배열엔 null값이 없이 모두 채워지게 됩니다.
그러나 while문은 종료조건을 충족시키지 못해 i++가 계속 될 것이고, ArrayIndexOutOfBoundsException이 발생할 것 같네요
EOF를 이용하여 풀어보시는 것을 추천드립니다!
dlaekgns2004 6년 전
이클립스에서는 잘 되는데.. 왜 런터임에러라고 뜨죠..?
import java.io.*;
public class Main {
public static void main(String[] args) throws IOException {
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String test[]=new String[100];
for(int i=0; i<100; i++){
test[i]=br.readLine();
if(test[i]==null)
break;}
int i=0;
while(test[i]!=null){
System.out.println(test[i]);
i++;
}
}
}