Answered step by step
Verified Expert Solution
Question
1 Approved Answer
String fileName is read from input. The try block opens a file named fileName for output. Three integers are read from input, and each integer
String fileName is read from input. The try block opens a file named fileName for output. Three integers are read from input, and each integer is written into the file. Write the finally block to perform the following tasks, if the output file is open:
Write to the file numValuesRead, followed by values read" and a newline.
If numValuesRead is greater than zero, write to the file "Last value is: followed by chiveLast and a newline.
Close the file. import java.util.Scanner;
import java.ioFileOutputStream;
import java.ioPrintWriter;
public class WriteLastChiveFile
public static void mainString args
Scanner scnr new ScannerSystemin;
PrintWriter chiveInWriter null;
String fileName;
int chiveValue;
int numValuesRead ;
int chiveLast ;
fileName scnrnext;
try
chiveInWriter new PrintWriternew FileOutputStreamfileName;
for numValuesRead ; numValuesRead ; numValuesRead
chiveValue scnrnextInt;
chiveInWriter.printlnchiveValue;
chiveLast chiveValue;
catch Exception e
System.out.printlnError;
Your code goes here
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