Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How do I write on a new line everytime.. my code keeps writingontop of the same

ID: 3618727 • Letter: H

Question

How do I write on a new line everytime.. my code keeps writingontop of the same line.
I use NetBeans IDE
Here is my code

for (int i = 0; i < 101; i++)
    {

    
        if (isPrime(i) ==true){

           String Num = Integer.toString(i);
           //Writer output = null;
           File file = new File("write.txt");


           BufferedWriter output = new BufferedWriter(newFileWriter(file));
           System.out.println(Num);
           
           output.write(Num);
           output.newLine();
           output.close();
           
           
           
         
           
        }

      
    }

Explanation / Answer

File file = newFile("write.txt");
BufferedWriter output = new BufferedWriter(newFileWriter(file));

for (int i = 0; i < 101; i++)
    {

        if (isPrime(i) ==true){

           String Num = Integer.toString(i);
           System.out.println(Num);
           output.write(Num);
           output.newLine();
        }

output.close();
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote