I've figured it out...somehow
![:D](./images/smilies/icon_biggrin.gif)
. I coded a try-catch block. It seems that a try-catch is still necessary even if you are not really expecting an error to occur.
However, I still haven't figured out how to terminate input when the end is not specified (again, in contrast to those problems which specify the number of test cases, or have "terminator" inputs, which usually involves zeroes). My current code template:
Code: Select all
public static void main(String[] args) throws IOException{
try{
InputStreamReader isr = new InputStreamReader(System.in);
BufferedReader lineInputReader = new BufferedReader(isr);
String foo = lineInputReader.readLine();
boolean firstTime = true;
while(foo != null){
//These conditional lines handle proper line-breaking
if(firstTime){
firstTime = false;
}
else{
System.out.print("\n");
}
//Process input...
foo = lineInputReader.readLine();
}
lineInputReader.close();
isr.close();
System.exit(0);
}
catch(Exception e){
}
}
Anything wrong I'm doing?