Many beginner programs rely on keyboard input read through
System.in. DrJava provides full support for this. There are two ways to use
System.in in DrJava. First, you can invoke a method in your code that relies on
System.in in the Interactions Pane. When you do this, the System.in input box will appear. Type your input, and press Return.
Alternatively, you can use the
System.in.read() method in the Interactions Pane directly. When the input box appears, type your text and then either press Return.
When the the input box appears in the Interactions Pane, you can choose to close the input stream by selecting the menu item "Tools, Interactions & Console, Close System.in", or by pressing the keyboard shortcut for it, which is
Ctrl-D . The shortcut is labeled
Close System.in in the Key Bindings section of the preferences.
Here is an example of closing the input stream. The text in square brackets was entered by the user.
Welcome to DrJava. Working directory is /Users/Shared/drjava > System.in.read()  49 > System.in.read() 10 > System.in.read() // press Ctrl-D now  -1 >
The user first types '1' and then presses Return. This lets DrJava read a 49, which is the ASCII code for the character '1', and then 10, which is the ASCII code for the new line created by Return. In the second input box, the user pressed Ctrl-D immediately to close the input stream. This lets DrJava read -1, indicating of the end of the stream.