title: Store random numbers in a text file (Java)
body: <p>I have made a code that creates 10 random numbers, I want to store these numbers in a text file but it only stores the last number 10 times, how do I fix this? I'm very new into coding, thanks in advance!</p>
  
  <pre><code>import java.io.*;
  import java.util.Random;
  
  public class Dices
  {
      public static void main( String[] args )
      {
          Random ran = new Random();
          int number = 0;
  
          for (int x = 0; x &lt;10; x++) {
              number = ran.nextInt(6)+1;
              //System.out.println(number);
  
          }
  
  
  
              try (PrintWriter file = new PrintWriter(
                      new BufferedWriter(
                              new FileWriter("test1.txt")));
              ) {
  
                  for (int i = 1; i &lt;= 10; i++) {
                      file.println(number);
                  }
  
              } catch (IOException e) {
                  e.printStackTrace();
              }
  
              System.out.println("File test1.txt has been created!");
  
  
          }
      }
  </code></pre>