Input File for Sum Program

Classic programmed-learning exercises, refreshed for modern Java and presented in the current MrStyner.com portfolio style.

Modern Java noteThis archive has been refreshed for Java 25 LTS. Core language concepts remain useful, while outdated setup instructions and browser-era Java are labeled or replaced. Java 26 is the current feature release; Java 25 is used here as the stable teaching baseline.
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:/users/default/JavaLessons>java AddTwo < input.txt

Enter first number:
Enter second number:
Sum: 19

C:/users/default/JavaLessons>

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. Negative numbers can start with -, but positive number cannot start with a plus. The number can be separated by spaces and can be preceeded by spaces or blank lines. This input file will work:

12
-7

As will this:

12     -7

But not this:

12 +7

QUESTION 9:

What is wrong with the second input file?