Terminating Input in Java
Posted: Tue Jan 19, 2010 4:02 pm
Hello. As I see it, the judge uses command-line input. While some problems give a "terminator" input (e.g. if two integers are given per line in an input, the "terminator" input is usually "0 0"), others do not. How do I go about that in Java? This is what I am doing:
I received a Runtime Error with the above code and so I guess the judge is complaining about how I handle the (undetermined) last test case. Am I correct in my guess? If so, what is an advisable workaround?
Code: Select all
public static void main(String[] args) throws IOException{
BufferedReader lineInputReader = new BufferedReader(new InputStreamReader(System.in));
String foo = lineInputReader.readLine();
while(foo != null){
String[] bar = foo.split(" ");
//Some code here concerning the problem...
foo = lineInputReader.readLine();
}
lineInputReader.close();
}