In AP Computer Science A, a logic error is a mistake in the algorithm or program that causes it to behave incorrectly or unexpectedly. The code compiles and runs fine; you only catch a logic error by testing the program with specific data and comparing the actual output to the expected output (EK 1.1.C.2).
A logic error is the sneakiest of the three error types in AP CSA. The code follows all of Java's rules, so the compiler is happy. The program runs all the way through, so there's no crash. But the answer is wrong. Maybe your average calculator divides by the wrong number, or your loop adds up four scores instead of five. The computer did exactly what you told it to do. The problem is that what you told it to do wasn't what you meant.
That's why the CED says logic errors are "detected by testing the program with specific data to see if it produces the expected outcome" (EK 1.1.C.2). No tool flags them for you. You have to know what the correct output should be, run the program, and notice the mismatch. The classic AP example is an off-by-one mistake, like starting a loop at i = 1 instead of i = 0, which quietly skips the first element and gives a wrong total without any error message at all.
Logic errors live in Topic 1.1 (Why Programming? Why Java?) in Unit 1, under learning objective AP Comp Sci A 1.1.C: Identify types of programming errors. The CED defines three categories you need to keep straight: syntax errors caught by the compiler (EK 1.1.C.1), logic errors caught by testing (EK 1.1.C.2), and run-time errors that crash the program during execution (EK 1.1.C.3). The whole skill being tested is matching the symptom to the error type. "Won't compile" means syntax. "Crashes with an exception" means run-time. "Runs fine but the answer is wrong" means logic. This matters far beyond Topic 1.1, because every loop, conditional, and array problem for the rest of the course is a chance to write (and hopefully catch) a logic error.
Keep studying AP® Computer Science A Unit 1
Run-time errors and exceptions (Unit 1)
These are the logic error's closest sibling and easiest to mix up. A run-time error makes the program terminate abnormally, like an ArrayIndexOutOfBoundsException. A logic error never crashes anything. Here's the twist the exam loves: a logic mistake in your code, like writing i <= arr.length instead of i < arr.length, can be what causes the run-time exception. The mistake is in your logic; the crash is the run-time symptom.
Syntax errors and the compiler (Unit 1)
The compiler checks code against Java's grammar rules and refuses to run anything that breaks them (EK 1.1.B.2). That's the dividing line. If the compiler catches it, it's a syntax error. The compiler cannot catch a logic error because logically-wrong code is still grammatically-perfect Java.
Algorithms and sequencing (Unit 1)
Topic 1.1 defines algorithms as step-by-step processes where order matters (EK 1.1.A.1 and 1.1.A.2). A logic error is what happens when the algorithm itself is flawed: steps in the wrong order, a step missing, or a step that does the wrong thing. The program faithfully executes a broken plan.
Loops and array traversal (Units 2 and 4)
Logic errors get introduced in Unit 1 but actually show up everywhere loops and arrays do. Off-by-one bounds, accumulators that start at the wrong value, and conditions that use < when they need <= are the bread-and-butter logic errors you'll trace in iteration and array questions for the rest of the course.
Logic errors show up in multiple-choice questions that hand you a short program and ask you to categorize what's wrong or predict what happens. A typical stem describes a program that compiles successfully and runs to completion but prints an unexpected result, then asks which error type that demonstrates. The answer hinges on the symptom. Another common setup gives you a loop over an array, like one that uses i <= numbers.length as its condition, and asks you to identify both the crash (a run-time exception) and the underlying cause (a logic mistake in the loop bound). On FRQs, the connection is practical rather than vocabulary-based. Writing a correct loop bound or initializing an accumulator properly is exactly how you avoid losing points to your own logic errors, and tracing code by hand with specific test values is the skill the CED says detects them.
Both happen after compilation succeeds, which is why they get confused. The difference is the symptom. A run-time error terminates the program abnormally, usually with an exception like ArrayIndexOutOfBoundsException. A logic error lets the program finish normally but produce wrong or unexpected output. Quick test: did it crash? Run-time error. Did it finish but give the wrong answer? Logic error. And remember the overlap case the exam loves: a logic mistake (bad loop bound) can be the root cause of a run-time crash.
A logic error is a mistake in the algorithm or program that makes it behave incorrectly or unexpectedly, even though the code compiles and runs (EK 1.1.C.2).
Logic errors are found by testing the program with specific data and comparing actual output to expected output, not by the compiler or by a crash.
If a program won't compile it's a syntax error, if it crashes during execution it's a run-time error, and if it runs fine but gives the wrong answer it's a logic error.
Off-by-one mistakes in loops, like starting at index 1 or using <= instead of < with array length, are the most common logic errors on AP CSA questions.
A logic mistake in your code can cause a run-time error, so when a question asks about the cause versus the symptom, read carefully which one it wants.
The computer always does exactly what your code says, so a logic error means your code says something different from what you intended.
It's a mistake in the algorithm or program that causes incorrect or unexpected behavior, as defined in EK 1.1.C.2 of the CED. The code compiles and runs without crashing, but the output is wrong, like a test-average program that divides by 4 instead of 5.
No. The compiler only checks that your code follows Java's syntax rules (EK 1.1.B.2). Logically-wrong code is still valid Java, so the only way to detect a logic error is to test the program with specific data and check whether the output matches what you expected.
A run-time error terminates the program abnormally during execution, usually with an exception like ArrayIndexOutOfBoundsException. A logic error lets the program run to completion but produce a wrong answer. Note that a logic mistake, like looping with i <= arr.length, can be the cause of a run-time crash.
Yes, that's exactly what makes logic errors tricky. The program compiles, executes, and finishes normally. It just produces incorrect or unexpected output, which is why the CED says you detect them through testing rather than through compiler messages or crashes.
Starting a loop at i = 1 instead of i = 0 when summing an array, which silently skips the first element and gives a wrong total. Other classics include using < when you meant <=, dividing by the wrong count when averaging, and initializing an accumulator to the wrong value.
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.