我不确定为什么,但代码在到达循环部分时停止。我等了 10 分钟……但仍然没有任何改变。这不是一个无限循环。
PrintWriter out = new PrintWriter(new File("CollectingTheData.txt"));
File dataCollection = new File("CollectingTheData.txt");
Scanner inF = new Scanner(dataCollection);
System.out.println("\nSimulating Trials Now...One Moment Please...");
RandomSquirels = (int)(Math.random() * 11 + 1);
while (RunCount <= TrialNumber) {
while (RandomSquirels != 10) {
out.println(RandomSquirels);
}
out.close();
RunCount++;
}
while (inF.hasNextLine()) {
NumRead = Integer.parseInt(inF.nextLine());
SquirelTotal += NumRead;
}
inF.close();
CalculationsForAv = (double)SquirelTotal / (double)TrialNumber;
System.out.println("The results! \nThe Average Number of \nSquirels Observed until Observing a Fox Squirrel: " + CalculationsForAv);
我只包含了代码的相关部分。导入所有必要的内容并定义所有变量。