EDIT: Fixed the code a little so the loop part isn't an issue, issue now is that the average isn't generating
The purpose of this program is to run an experiment of multiple trials seeing how many squirrels you see before seeing a fox squirrel.
I am getting no output from the average, it is giving me a value of 0.0. I use repl.it to compile, does that affect it from writing into the text file? I have the text file created in the same folder as the repl.it.import java.io.IOException; import java.io.PrintWriter; import java.io.File; import java.util.Scanner; import java.util.Random; class Main { public static void main(String[] args) throws IOException { Scanner input = new Scanner(System.in); File fileName = new File("squirrel.txt"); Scanner inFile = new Scanner(fileName); PrintWriter outFile = new PrintWriter(new File("squirrel.txt")); Random ran = new Random(); System.out.println("Welcome to the Fox Squirrel Simulator"); System.out.println(); System.out.println("How many trials should be simulated?"); System.out.println("Please enter a number greater than 1000: "); int trialNum = input.nextInt(); if (trialNum < 1000) { System.out.println("\tError, please try again."); System.out.println("How many trials should be simulated?"); System.out.println("Please enter a number greater than 1000: "); trialNum = input.nextInt(); } int initialTrialNum = trialNum; System.out.println("trialNum is " + trialNum); System.out.println(); System.out.println("Simulating trials, please wait..."); int squirrelsSeen; int foxSquirrel; int trialsDone; for (trialsDone = 1; trialsDone <= trialNum; trialsDone++) { squirrelsSeen = 0; for(foxSquirrel = 0; !(foxSquirrel == 10); squirrelsSeen++) { foxSquirrel = ran.nextInt(11); } outFile.println(squirrelsSeen); System.out.println(squirrelsSeen); } String token = ""; int sum = 0; int fileInt = 0; while(inFile.hasNext()) { token = inFile.next(); fileInt = Integer.parseInt(token); sum += fileInt; } double average = (double)sum/(double)initialTrialNum; System.out.println("The results! The average number of squirrels \n saw until a fox squirrel was spotted is: " + average); } }