lundi 22 mai 2017

Trying to put random strings into a file

I am trying to insert random strings into a .txt file. My code is as follows:

import java.util.*;
import java.io.*;

class fileProcessing{
   public static void main (String[] args) throws Exception{
      letter();
   }

   public static void letter() throws Exception{
      int count = 0;
         PrintStream out = new PrintStream(new File("nums.txt"));
            while (count < 7 ){
              Random rand = new Random();
                  int randomNum = 97 + rand.nextInt((122 - 97) + 1);
                     char a = (char)randomNum;
                        out.print(a);
                        count++;
      }
   }
}

I'm trying to put a row of 7 random letters in a .txt file about 400 or so times. My code allows me to put in only a row of 7 letters. I'm not sure how to get the other 399 lines in. Any help would be appreciated. Thanks!




Aucun commentaire:

Enregistrer un commentaire