samedi 12 octobre 2019

How can I generate 30 random fractions and print them on different lines?

I am writing in Java Swing doing a homework problem where I have to print 30 random fractions with one on each line of a text file. I should do this using a function.

I am not sure what the best way to do it.

I know I could create many hundreds of lines to do this but I want to make my work much shorter.

public static int printer() throws IOException{
    FileWriter fileOutStream = new FileWriter("C:\\Users\\Auden\\Documents\\NetBeansProjects\\FractionGame\\src\\fractiongame\\equations");
    PrintWriter fileOutput = new PrintWriter (fileOutStream);
    int ran;

    ran = getRandomNumber();
    fileOutput.print(ran+"/");
    ran = getRandomNumber();
    fileOutput.print(ran);
    fileOutput.println("");  
    fileOutput.close();
    return ran;
}

I don't know how to use this to create multiple fractions on different lines.




Aucun commentaire:

Enregistrer un commentaire