01
Overview

Even/odd checks and sign-based counts.

Two of the most common single-pass tallies: how many evens, how many positives.

Evenness is tested with n % 2 == 0; sign with n > 0, n < 0, or n == 0. Counting how many elements fall into each category drives many AP-style problems.

Both can run in a single pass with three separate counters — one for each outcome.

On the AP exam, evenness and sign counts appear in tracing MCQs and in simple FRQs that classify input.

02
Core Concept

One pass, multiple counters, mutually exclusive branches.

Each element falls into exactly one bucket.

Even count

int evens = 0;
for (int n : arr) {
    if (n % 2 == 0) evens++;
}

Sign counts in one pass

int pos = 0, neg = 0, zero = 0;
for (int n : arr) {
    if (n > 0) pos++;
    else if (n < 0) neg++;
    else zero++;
}

The else if ladder ensures each element is counted exactly once.

Why else-if matters

Three independent if statements would also work — but they evaluate every condition. The ladder short-circuits as soon as a match is found, which is cleaner and slightly faster.

Negative modulo caution

-4 % 2 is 0 in Java, so even-checks work fine for negatives. But -5 % 2 is -1, not 1 — so testing odd via n % 2 == 1 fails for negative odd numbers. Better: n % 2 != 0.

03
Key Vocabulary

Evenness + sign vocabulary.

Used in classification problems.

Vocabulary
  • Evenness — divisibility by 2.
  • Modulo 2 — remainder when dividing by 2.
  • Sign — positive, negative, or zero.
  • Mutually exclusive — each input matches exactly one category.
  • Else-if ladder — chained conditions with single-match semantics.
04
AP Exam Focus

How these counts are tested.

Else-if structure and odd-check direction dominate.

Exam Focus
  • Odd via != 0. Safer for negatives.
  • Else-if ladder. Each input counted once.
  • Zero separately. Don't combine with positives or negatives.
  • Order doesn't matter for mutually exclusive conditions.
05
Worked Example

Classify an array.

Even, odd, positive, negative, zero counts in one pass.

Worked Example AP-style reasoning

Input: [3, -4, 0, 7, -2, 0, 5].

Evens: -4, 0, -2, 0 → 4.

Odds: 3, 7, 5 → 3.

Positives: 3, 7, 5 → 3.

Negatives: -4, -2 → 2.

Zeros: 0, 0 → 2.

Sanity: 3+2+2 = 7 (matches length). 4+3 = 7 (also matches).

06
Common Mistakes

Evenness and sign pitfalls.

Most are negative-number edge cases.

Watch Out
  • n % 2 == 1 for odd. Fails for negative odd numbers.
  • Counting zeros as positives or negatives. Treat separately.
  • Three independent ifs. Works but inefficient — use else-if.
  • Forgetting to reset counters. Always init to 0 before the loop.
07
Reference Table

Classification tests.

Safe forms for each.

Evenness & Sign Reference

AP Quick Reference
CategoryTestNote
Evenn % 2 == 0Works for negatives.
Oddn % 2 != 0Safe for negatives.
Positiven > 0Excludes 0.
Negativen < 0Excludes 0.
Zeron == 0Its own category.
08
Practice Tip

How to master classification counts.

Else-if ladder; safe odd test.

Practice Strategy
  • MCQ Practice — verify mutually exclusive branches don't double-count.
  • Java Lab — count evens/odds and pos/neg/zero in one loop. Verify sums equal input length.
  • FRQ Practice — use n % 2 != 0 when negatives might appear.
09
Section · 09

Practice — attempt these now.

AP-style assessments aligned to this lesson. Time them.

FRQ Practice 30 min 18 marks Pending

AP CSA Unit 09 Topic 05 Modulo Evenness and Sign Counting FRQ Practice

AP-style topic practice assessment

Start