---
title: "runSimulations — AP CSA Definition & 2018 FRQ Guide"
description: "runSimulations is a method that calls simulate repeatedly and returns the proportion of successes as a double. It anchors loops, counters, and casting on the AP CSA exam."
canonical: "https://fiveable.me/ap-comp-sci-a/key-terms/runsimulations"
type: "key-term"
subject: "AP Computer Science A"
unit: "Unit 2"
---

# runSimulations — AP CSA Definition & 2018 FRQ Guide

## Definition

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.

## What It Is

runSimulations is the classic "run it a bunch of times and report the success rate" [method](/ap-comp-sci-a/unit-3/abstraction-and-program-design/study-guide/o9VgVeIpKRYZ7N7rXfUz "fv-autolink"). It takes a number of trials, uses a [loop](/ap-comp-sci-a/key-terms/loop "fv-autolink") 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](/ap-comp-sci-a/unit-1/why-programming-why-java/study-guide/lVK6rmrBuug17i1Hna9z "fv-autolink") 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.

## Why It Matters

runSimulations lives in [Unit 2](/ap-comp-sci-a/unit-2 "fv-autolink") (Selection and Iteration), specifically Topic 2.7 While Loops. It directly supports [AP Comp Sci A](/ap-comp-sci-a "fv-autolink") 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.

## Connections

### While Loops (Unit 2)

runSimulations is a [while loop](/ap-comp-sci-a/unit-2/for-loops/study-guide/DJuLxKz6SiSAX2cEVmCt "fv-autolink") 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)](/ap-comp-sci-a/key-terms/off-by-one-error)

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](/ap-comp-sci-a/key-terms/accumulator-pattern "fv-autolink"). 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](/ap-comp-sci-a/key-terms/integer-division "fv-autolink"). runSimulations forces you to cast (e.g. (double) successes / numSimulations) so the proportion comes out as a real decimal.

## On the AP Exam

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.

## runSimulations vs simulate

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.

## Key Takeaways

- 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.

## FAQs

### What is the runSimulations method in AP Computer Science A?

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.

### Does runSimulations return an int or 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.

### What's the difference between simulate and runSimulations?

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.

### Is runSimulations still on the AP CSA exam?

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.

### Why does my runSimulations method always return 0.0?

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.

## Related Study Guides

- [2.7 While Loops](/ap-comp-sci-a/unit-2/while-loops/study-guide/7qGsGOh1UKALAWpJhZOi)

## Structured Data

```json
{"@context":"https://schema.org","@graph":[{"@type":"LearningResource","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/runsimulations#resource","name":"runSimulations — AP CSA Definition & 2018 FRQ Guide","url":"https://fiveable.me/ap-comp-sci-a/key-terms/runsimulations","learningResourceType":"Concept explainer","educationalLevel":"AP® / High School","about":{"@id":"https://fiveable.me/ap-comp-sci-a/key-terms/runsimulations#term"},"audience":{"@type":"EducationalAudience","educationalRole":"student"},"dateModified":"2026-06-11T05:27:19.845Z","isPartOf":{"@type":"Collection","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"},"publisher":{"@type":"Organization","name":"Fiveable","url":"https://fiveable.me"}},{"@type":"DefinedTerm","@id":"https://fiveable.me/ap-comp-sci-a/key-terms/runsimulations#term","name":"runSimulations","description":"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.","url":"https://fiveable.me/ap-comp-sci-a/key-terms/runsimulations","inDefinedTermSet":{"@type":"DefinedTermSet","name":"AP Computer Science A Key Terms","url":"https://fiveable.me/ap-comp-sci-a/key-terms"}},{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What is the runSimulations method in AP Computer Science A?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"Does runSimulations return an int or a double?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"What's the difference between simulate and runSimulations?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"Is runSimulations still on the AP CSA exam?","acceptedAnswer":{"@type":"Answer","text":"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."}},{"@type":"Question","name":"Why does my runSimulations method always return 0.0?","acceptedAnswer":{"@type":"Answer","text":"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."}}]},{"@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"AP Computer Science A","item":"https://fiveable.me/ap-comp-sci-a"},{"@type":"ListItem","position":2,"name":"Key Terms","item":"https://fiveable.me/ap-comp-sci-a/key-terms"},{"@type":"ListItem","position":3,"name":"Unit 2","item":"https://fiveable.me/ap-comp-sci-a/unit-2"},{"@type":"ListItem","position":4,"name":"runSimulations"}]}]}
```
