Write a program to create an output file, \"mydata.txt\", and write the numbers
ID: 3617830 • Letter: W
Question
Write a program to create an output file, "mydata.txt", andwrite the numbers 1 to 1000. Put 10 numbers on each line.
Format the output so that the columns line up perfectly.
1 2 3 4 5 6 7 8 9 10
11 12 13 14 15 16 17 18 19 20
Hint1:
Convert the number to a string and get its length. Then, print
the correct number of spaces before printing the number.
Hint2:
When checking the format, you will need to display the
numbers in a fixed-width font, like Courier, like below.
Hint3:
First, display the first 20 numbers on the console. Afterit's working,
print the numbers into the file.
Write a program to open "mydata.txt", read and sum up allnumbers
in the file. Print the sum on the console.
Explanation / Answer
Here is the program I made without considering the methods andclasses for reading and writing files. I hope you find it usefuland most important of all, don't forget to ask if you have anyworry or doubt about the solution. import javax.swing.*; import java.io.*; class tableNumbers { public static void main (String [] args) { int num=0, i, j; for(i=0; iRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.