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 squares(starting from 1) into a file named perfectsq.txt. Each number is on a separate line in the file.
Sample runs
Input 1:
5
Output 1:
1491625
Input 2:
10
Output 2:
149162536496481100
// add proper import statements so that
// the programs compiles fine
// your code starts here
// your code ends here
public class Test {
public static void main(String[] args) throws FileNotFoundException {
Scanner stdin = new Scanner(System.in);
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 =1; 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 blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!