Java Reference
In-Depth Information
Here is a sample run:
In the program, notice that main( ) begins like this:
Because System.in.read( ) is being used, the program must specify the throws
java.io.IOException clause. This line is necessary to handle input errors. It is part of Java's
exception handling mechanism, which is discussed in Chapter 9 . For now, don't worry
about its precise meaning.
The fact that System.in is line buffered is a source of annoyance at times. When you
press ENTER , a carriage return, line feed sequence is entered into the input stream. Further-
more, these characters are left pending in the input buffer until you read them. Thus, for
some applications, you may need to remove them (by reading them) before the next input
operation. You will see an example of this later in this chapter.
The if Statement
Chapter 1 introduced the if statement. It is examined in detail here. The complete form of
the if statement is
if( condition ) statement ;
else statement;
Search WWH ::




Custom Search