In AP Computer Science A, runSimulations is a method (famous from the 2018 FRQ frog simulation) that uses a loop to call a simulate method a given number of times, counts how many runs succeed, and returns the proportion of successful simulations as a double.
runSimulations is the classic "run it a bunch of times and report the success rate" method. It takes a number of trials, uses a loop to call a helper method called simulate that many times, keeps a counter of how many simulations return true, and then divides successes by total trials to return a proportion as a double.
The method became a named thing in AP CSA because of the 2018 FRQ Q1, which asked you to write a simulation of a frog hopping toward a goal. simulate ran one frog attempt and returned true or false. runSimulations was the wrapper that repeated that experiment. The pattern packs three core skills into one method. You need iteration (EK 2.7.A.1, repeating code as long as a Boolean condition is true), an accumulator variable to count successes, and double arithmetic so the division doesn't silently truncate to 0.
runSimulations lives in Unit 2 (Selection and Iteration), specifically Topic 2.7 While Loops. It directly supports AP Comp Sci A 2.7.A, identifying when an iterative process is required (you can't run 1,000 trials without a loop), and AP Comp Sci A 2.7.B, developing code with while loops and determining what they produce. It's also a magnet for two classic bugs the CED calls out. An off by one error (EK 2.7.A.4) means you run one trial too many or too few, and a loop condition that never becomes false gives you an infinite loop (EK 2.7.A.2). On top of that, the "proportion as a double" requirement tests whether you remember that int divided by int throws away the decimal. This one method is basically a Unit 2 skills checklist.
Keep studying AP® Computer Science A Unit 2
While Loops (Unit 2)
runSimulations is a while loop with a job. The Boolean condition (something like count < numSimulations) is checked before every iteration, including the first, exactly as EK 2.7.B.1 describes. If you pass in 0 trials, the body never runs at all.
Off by One Error (Unit 2)
The single most common way to lose points on this pattern. Starting your counter at 1 instead of 0, or using <= instead of <, makes runSimulations execute one extra or one missing trial, which skews the proportion you return.
Loop Accumulators (Unit 2)
Counting successes inside the loop is the accumulator pattern. You declare a counter before the loop, update it inside the loop only when simulate() returns true, and use the final total after the loop ends. This same structure shows up everywhere from array traversals to String processing later in the course.
Integer vs. Double Division (Unit 1)
successes / numSimulations with two ints gives you 0 almost every time, because Java truncates integer division. runSimulations forces you to cast (e.g. (double) successes / numSimulations) so the proportion comes out as a real decimal.
runSimulations comes straight from the 2018 FRQ Q1, where the College Board asked you to write a simulation of a frog hopping toward a goal. Part of the question required exactly this method, looping a specified number of times, calling simulate each iteration, counting true results, and returning the success proportion as a double. On FRQs, you earn points for a correct loop bound (no off by one error), correctly calling the helper method, accumulating the count, and getting the double division right. In multiple choice, the same pattern appears as "what does this method return" questions where the trap answer comes from integer division or a loop that runs one time too many.
simulate runs ONE trial and returns a boolean for that single attempt (did the frog reach the goal this time?). runSimulations is the outer method that calls simulate over and over and reports the overall success rate as a double. Mixing them up on an FRQ, like putting the repetition logic inside simulate, costs points because each method has one clearly defined job.
runSimulations loops a specified number of times, calls the simulate method once per iteration, and counts how many simulations succeed.
It returns the proportion of successful trials as a double, so you must cast or use double arithmetic to avoid integer division returning 0.
The pattern comes from the 2018 AP CSA FRQ Q1, which simulated a frog hopping toward a goal within a limited number of hops.
Watch your loop bounds. An off by one error makes the method run one trial too many or too few, which changes the returned proportion.
Per EK 2.7.B.1, the loop condition is checked before every iteration, so if the number of simulations requested is 0, the body never executes.
runSimulations and simulate split the work on purpose. simulate handles one trial, runSimulations handles repetition and the math.
It's a method from the 2018 FRQ Q1 (the frog simulation) that uses a loop to call simulate a given number of times, counts the true results, and returns the proportion of successful simulations as a double.
A double. The whole point is the proportion of successes, like 0.37, so you have to cast at least one operand of the division to double. Two ints divided in Java truncate to an int, which would give you 0.
simulate performs one trial and returns a boolean (true if that single attempt succeeded). runSimulations is the wrapper that calls simulate repeatedly, counts successes, and returns the overall success rate. One trial versus many trials.
Not as a required vocabulary word, but the pattern absolutely is. It's a textbook application of Topic 2.7 (LO 2.7.B, developing iterative processes with while loops), and simulation-style FRQs that ask you to repeat a trial and report results keep appearing.
Almost certainly integer division. If successes and numSimulations are both ints, successes / numSimulations truncates to 0 whenever successes is smaller. Cast one of them, like (double) successes / numSimulations, before dividing.
Connect this key term to the AP exam workflow: review the course, practice questions, and check related study tools.
Review units, study guides, and course resources.
Check this vocabulary in multiple-choice context.
Apply key concepts in written AP responses.
Estimate the exam score you are working toward.
Review the highest-yield facts before practice.
Put the full course together before test day.