Sunday, 27 November 2016

java - Why is nextLine() returning an empty string?

Actually it doesn't answer the question completely(why your code isn't working) but you may use following code.



int n = Integer.parseInt(readInput.readLine());
for(int i = 0; i < n; ++i) {
String line = readInput().readLine();

// use line here
}


As for me it's more readable and even may save your time in such rare cases when testcases are incorrect(with extra info at the end of file)



BTW, seems you take part in some programming competition. Make note, that Scanner may be quite slow to input a lot of data. you may consider using BufferedReader with possible StringTokenizer (not needed in this task)

No comments:

Post a Comment

c++ - Does curly brackets matter for empty constructor?

Those brackets declare an empty, inline constructor. In that case, with them, the constructor does exist, it merely does nothing more than t...