reference pages: 323-326
I don't understand how the program knows to wait for input from user after those line of codes:
Code:
System.out.print("Enter an integer: ");
Code:
System.out.print("Enter a double value: ");
Code:
System.out.print("Enter a string: ");
does this line of code:
Code:
private StreamTokenizer tokenizer = new StreamTokenizer( new BufferedReader( new InputStreamReader(System.in) ) );
means during execution each time print method is called, the program waits for input? I drew this conclusion based on the fact that after each print method is called, the program waits for input but after each println the program execute the next instruction.
(I read in the chapter what StramTokenizer, BufferedReader, and InputStreamReader does)
here's the code snippet from the TRY IT OUT on page 325.
Code:
FormattedInput kb = new FormattedInput();
for( int i = 0; i < 5; ++i ){
try{
System.out.print("Enter an integer: ");
System.out.println("Ineger read:" + kb.readInt());
System.out.print("Enter a double value: ");
System.out.println("Double value read: " + kb.readDouble());
System.out.print("Enter a string: ");
System.out.println("String read: " + kb.readString());
}
catch(InvalidUserInputException e){
System.out.println("InvalidUserInputException thrown.\n" + e.getMessage());
}
}