I have tried to create a program which reads text lines from a standard input and does something with those lines. I have done exactly as all the threads suggest that go over this issue (there were many) but still, my program does not terminate. Say I input 2 lines of text, I want my program to go over those two lines to do something and then stop waiting for more input.
Should this code not print both lines of my sample input and then proceed to print what is after that?
I've tried doing this, Replacing BufferedReader with Scanner also, but ended up with the same result.
Sample input:
hello
olloh
Here is the code:
public class Task2 {
public static void main(String[] args) throws IOException {
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
String line = reader.readLine();
while (line != null) {
System.out.println(line);
line = reader.readLine();
}
System.out.println("Read all the lines");
System.err.print("Task 2");
}
}
ยดยดยด