Question: Java Program Write a program that reads an ASCII file that contains a set of numbers of type int and outputs all the numbers to
Java Program
Write a program that reads an ASCII file that contains a set of numbers of type int and outputs all the numbers to another file, but without any duplicated numbers.
Assume that in the input file, the numbers, one per line, are listed from smallest to largest. After the program is run, the new output file will contain all the numbers in the original file, but no number will appear more than once in the file. The numbers in the output file should also be listed from smallest to largest.
In addition, the program should compute the average of those retained distinct numbers and then save it as the last line of the output file.
Your program should first obtain both input and output file names from the user.
Your program should catch and handle potential exceptions when needed. You cannot use a data structure (e.g., array or list) in this program to help remove possible duplicated numbers.
A sample run of the program:
Please enter the name of an ASCII file that contains a sorted list of integer numbers, one per line:
myNums.in
Please enter the name of the output file that saves the result from the program:
myNums.out
Do you want to run the program again (y for yes and n for no):
Once you complete the program above, please consider writing another set of programs that perform the same task with binary input/output files. Although this part is NOT required, you are strongly encouraged to do so to help you learn the process of reading/writing binary files in Java.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
