Question: Write a program that creates an output file named randNums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the

Write a program that creates an output file named randNums.txt. Open the file and write 100 random integers between -50 and +50 (inclusive) to the file. Be sure to handle any file IO exceptions. Remember to close the file.

Having the file randNums.txt created, write a program that opens this file for input. Create two output files pos.txt and neg.txt. Read through the input file, one line at a time, converting each line into an integer (no exception handling, yet). If the number is positive, write it to pos.txt (one number per line). If the number is negative, write it to neg.txt. If the number is 0, do nothing. Be sure to close all files.

We created randNums.txt, so we know all the numbers are valid. What if, instead, you used my data file CS21randNums.txt? This file may (it does!) have invalid data. Modify your program from part b. to use exception handling to simply disregard any invalid data and continue with the next line of data. Try it out with CS21randNums.txt

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 Databases Questions!