Question: Complete the following program that writes the first nperfect squares ( starting from 1 ) into a file named perfectsq.txt . Each number is on
Complete the following program that writes the first nperfect squaresstarting from into a file named perfectsq.txt Each number is on a separate line in the file.
Sample runs
Input :
Output :
Input :
Output :
add proper import statements so that
the programs compiles fine
your code starts here
your code ends here
public class Test
public static void mainString args throws FileNotFoundException
Scanner stdin new ScannerSystemin;
int n stdin.nextInt;
instantiate a PrintWriter object for writing to file
perfectsq.txt
your code starts here
your code ends here
for int i ; i n; i
Write each square to the file
your code starts here
your code ends here
close the PrintWriter
output.close;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
