import java.util.Scanner;
class newClass {
public static void main(String args[]) {
Scanner s = new Scanner(System.in);
while (s.hasNext()) {
System.out.println(s.next());
}
s.close();
}
}
This program does not return to prompt (I have been running it through the Terminal). Why is that? How can I correct it?
Because
s.hasNext()will block until further input is available and will only return false if it encounters end of stream.From the docs:
On a unix system you can end the stream by typing Ctrl+D which correctly returns control to the prompt, (or terminate the whole program by typing Ctrl+C).
You can either
System.in.close()programatically from another thread.