The Question

Write a program called Q1.java that reads lines from standard input (the keyboard) until there are no more lines to read. Some of these lines will contain "hidden" numbers; i.e. the line will contain digits (among the other characters) that form an integer. For example, the line "Thi4s i4s a7n exam9ple", contains the number 4479. Ignore plus/minus signs. For each line that conains a hidden number, your program should print out that number alone on a line. If the line does not contain a hidden number, nothing should be printed. When it has read all input lines, your program should print out the total of all the hidden numbers read. (If no hidden numbers have been read, then the total is 0.)

The output should conform to that in the sample run of a correct program shown below. Note that, in this sample run, the % sign is not part of the program output.

Sample Run

%
% java Q1
Enter lines containing hidden numbers:
Her1e is0 the fir0st line.  
100
Here is the second line.
And here is15 th5e last line.
155
The total is 255
%

Useful APIs

Here (again) are the common APIs that you may access:

Java 1.5 API
Type API

Submitting Your Work

Here is the command to submit your work (further details regarding the submit command can also be obtained by typing man submit
Once again, you are encouraged to submit regularly. Newer submissions overwrite older ones.

submit 1020 labtest2W7 Q1.java