Question: Write a java class ReadNumbers.java The file will read a text file numbers.txt. Each line of numbers.txt contains an integer number. The first line of

Write a java class ReadNumbers.java

The file will read a text file numbers.txt.

Each line of numbers.txt contains an integer number.

The first line of numbers.txt will contain how many numbers it will contain.

After first line there will be integers at each line. -1 will indicate the end of file.

Example:

10

1

20

37

3

4

23

90

11

13

19

-1

In the above file the first line contains a 10. So there will be 10 lines after the first line. Each of the 10 lines will contain an integer. At the end when -1 is read it is considered as end of file and there is no more input to read.

The program will initialize an array with size equal to the first integer in the file. In our above example it will initialize the array with size 10.

Then it will read each integer after the first line and place it in the array. The array for our above example will be like:

1

20

37

3

4

23

90

11

13

19

The program will then determine the maximum, minimum, average and sum for the integers in the array.

The program then creates another output text file as output.txt

Then it writes the maximum, minimum, average and total into the output.txt file

The format of the output.txt file for our above example will be like:

Maximum: 90

Minimum: 1

Total: 221

Average: 22

Use proper exception handling for files.

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!