Answered step by step
Verified Expert Solution
Question
1 Approved Answer
mport java.io . File; import java.io . FileNotFoundException; import java.io . PrintWriter; import java.util.Scanner; / * * This program reads a file with numbers, and
mport java.ioFile;
import java.ioFileNotFoundException;
import java.ioPrintWriter;
import java.util.Scanner;
This program reads a file with numbers, and writes the numbers to another
file, lined up in two columns, and followed by the total.
public class Total
public static void mainString args throws FileNotFoundException
Prompt for the input and output file names
Scanner console new ScannerSystemin;
System.out.printInput file: ;
String inputFileName console.next;
String outputFileName "out.txt;
Construct the Scanner and PrintWriter objects for reading and writing
File inputFile new FileinputFileName;
Scanner in new ScannerinputFile;
PrintWriter out new PrintWriteroutputFileName;
Read the input and write the output
double total ;
while inhasNextDouble
double value innextDouble;
out.printff
valuevalue;
total total value;
out.printfTotal: f
total;
inclose;
out.close;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started