Question: A Java program that reads the file input.txt and calculates and prints the average of all integer numbers in this file. SAMPLE OUTPUT: throws FileNotFoundException

A Java program that reads the file "input.txt" and calculates and prints the average of all integer numbers in this file. 

SAMPLE OUTPUT:

throws  FileNotFoundExceptiontry/catch

OUTPUT SAMPLE #1 for input.txt: 1 2 3 4 5 6 x x x 8 12 x x 34 x x 10 20
Number # 1 is: 1
Number # 2 is: 2
Number # 3 is: 3
Number # 4 is: 4
Number # 5 is: 5
Number # 6 is: 6
Number # 7 is: 8
Number # 8 is: 12
Number # 9 is: 34
Number # 10 is: 10
Number # 11 is: 20
The average of 11 numbers/file = 9.55

OUTPUT SAMPLE #2 for input.txt: xxxxx x x x x xx x x x x x
The file doesn't contain any integers. Exit program!

OUTPUT SAMPLE #1 for input.txt: 1 2 3 4 5 6 x x x 8 12 x x 34 x x 10 20
Please input the name of the file to be opened: input.tx
--- File Not Found! ---

OUTPUT SAMPLE #2 for input.txt: 1 2 3 4 5 6 x x x 8 12 x x 34 x x 10 20
Please input the name of the file to be opened: input.txt
Number # 1 is: 1
Number # 2 is: 2
Number # 3 is: 3
Number # 4 is: 4
Number # 5 is: 5
Number # 6 is: 6
Number # 7 is: 8
Number # 8 is: 12
Number # 9 is: 34
Number # 10 is: 10
Number # 11 is: 20
The average of 11 numbers/file = 9.55

OUTPUT SAMPLE #3 for input.txt: xxxxx x x x x xx x x x x x
Please input the name of the file to be opened: input.txt
The file doesn't contain any integers. Exit program!

 

2.  A Java program that reads the file "input.txt" and writes all even values from this file into a new file called "output.txt." 

 

SAMPLE OUTPUT:  

throws  FileNotFoundExceptiontry/catch

OUTPUT SAMPLE #1 for input.txt: xx x xx 10 12 1 3 5 34 x 2 5 7 9 x x 44
Found 11 numbers/file.
Open the file output.txt to get the output.
output.txt: 10 12 34 2 44 

OUTPUT SAMPLE #2 for input.txt: xx xx xx  x  x x xxx xxx
The file doesn't contain any integers. Exit program!

OUTPUT SAMPLE #1:  
Please input the name of the file to be opened: input.tx
--- File Not Found! ---

OUTPUT SAMPLE #2 for input.txt: xx x xx 10 12 1 3 5 34 x 2 5 7 9 x x 44
Please input the name of the file to be opened: input.txt
Found 11 numbers/file.
Open the file output.txt to get the output.
output.txt: 10 12 34 2 44

OUTPUT SAMPLE #3 for input.txt: xx xx xx  x x xxx x xx x x x
Please input the name of the file to be opened: input.txt
The file doesn't contain any integers. Exit program!





Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!