The code for these Laboratory exercises require you to build each program from scratch. No code exists on your jump drive for these programs. The output these programs generate and send to the Console window must match what is shown in the Console Output document – this includes the wording of messages and the line spacing between printed items.
#1 – Name it C13e1 // Chapter 13 Exercise 1 – Writing to a Text File
This program writes a series of integer numbers to a file named C13e1.txt and contains only one method – the required main method. The main method throws IOException. You must import java.io.* into your program.
Within the main method, do the following:
- Declare a PrintWriter object named outFile that points to the C13e1.txt file.
- Set up a for loop where the startup action is int myNumber = 5; the true/false expression is myNumber <= 100; and the update action is myNumber + 5. Within the for loop, do the following:
- Write to the C13e1.txt file using outFile.println(myNumber).
- After the for loop, do the following:
- Close outFile.
- Display the entire “successfully created” message to the Console window.
- Display a blank line and the End of Program message in the Console window.