When I run the following code and type CTRL-Z (on Windows PC), then System.in.read() should return -1 and System.out.println("1st echo - " + i) and
System.out.println("2nd echo - " + i) should echo it on the screen. This is the way things happen if CTRL-Z is the first thing I type after running the program. If I type CTRL-Z after typing some other input, then I do NOT get the first echo! Can somebody explain? Thanks in advance!
<PRE>
import java.io.*;
public class
test {
public void run() {
int i = 0;
try { while (i!=-1) {
i = System.in.read();
System.out.println("1st echo - " + i);
System.out.println("2nd echo - " + i);
}
} catch(IOException ioe) { System.out.println("caught IOException"); }
}
public static void main(
String[] args) {
new test().run();
}
}
</PRE>