This is the code I have:
import java.io.DataInputStream;
import java.io.InputStream;
public class TestClass {
public static void main(String[] args) throws Exception {
InputStream inputStream = new DataInputStream(System.in);
int read = inputStream.read();
System.out.println(read);
}
}
When I run this code inputStream will wait for input from the standard input which is fine. When I type 'a' in keyboard, I expect 97 to be printed immediately in the console. However this code requires me to hit 'Enter' after I type 'a'.
If I simply hit 'Enter' integer 10 will be shown in the console.
How can I modify the code so that as soon as I hit 'a' in the keyboard I see the integer 97? What is so special about the Enter button in this case? Why do I need to hit Enter?