Question: 2.[4 pts] The following program will read integers from a text file called input1.txt, it then computes the sum of all the integers inside the
![2.[4 pts] The following program will read integers from a text](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2024/09/66f549004abbc_03966f548ffddbcc.jpg)
2.[4 pts] The following program will read integers from a text file called input1.txt, it then computes the sum of all the integers inside the file and saved the result as follows inside an output file called output.txt (Mark your answer with the corresponding sub question's number clearly) The sum is: ?? where ?? will be replaced by the actual computation result. According to the program's description, write codes to finish the program import java.io. import java.util.Scanner public class ReadWrite TextFileExample { public static void main(String[] args) { int num, sum = 0 try { //(Q2.1) Create a File object from input1.txt //(Q2.2) create a Scanner object from above File object Scanner input = //- while (input hasNext()) { //(Q2.3) read one integer from input1.txt 1/(Q2.4)compute the sum Il- 3 input.close(); Q2.5) create a text file object which you will write the output to Il(Q2.6) create a PrintWriter object //(Q2.7) write to above output file by using print() & println() methods //(Q2.8) close the file ---- } catch (FileNotFoundException exception) { System.out.println ("The file " + file.getPath() + "was not found."); ) }/lend main() lend class
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
