go to previous page   go to home page   go to next page highlighting
C:\temp>java AddTwo
Enter first number: 4   13
Enter second number:  Sum: 17

Answer:

The first group of characters that could be converted to an int was read, then scan.nextInt() stopped scanning the line. When it was called again, it resumed scanning the same line and collected the 13.


Input File for Sum Program

Here is an input file for use with this program. The file is named input.txt.

12
7

Here is a sample run of the program with this data file:

C:\temp>java AddTwo < input.txt

Enter first number:
Enter second number:
Sum: 19

C:\temp>

The input file for this program cannot contain any characters that are not part of an integer. Each number must contain only the digits 0 through 9, minus -, and plus +. The number can be separated by spaces or blank lines. This input file will work:

12
-7

As will this:

12     -7

But not this:

12xxx7

or this:

12, 7

QUESTION 9:

Will this input file work correctly?

12  7   -4    6

go to previous page   go to home page   go to next page