mercredi 11 mars 2015

How do I create a file with 100 random numbers with 15 numbers on each line?



My assignment is to create a new file with 100 random numbers to a new file with 15 numbers on each line. I can get it to print out 100 random numbers, but when I try to get it to print 15 numbers per line, the program never finishes running.



import java.util.*;
import java.io.*;
public class Random100{
public static void main(String [] args)throws IOException
{
PrintWriter out = new PrintWriter(new File("random.txt"));
Random rand = new Random();
int number, count=0, countTwo=0;
while(count!=100)
{
while(countTwo<=15)
{
number=rand.nextInt(100)+1;
out.print(number);
count++;
countTwo++;
}
out.println();
}
out.close();
}
}



Aucun commentaire:

Enregistrer un commentaire