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

Answer:

Without the parentheses the second "+" would mean "string concatenation," not addition.


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>

Warning: 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