← All examples

for-each

Java Loops

for (T x : c)

Flowchart (ISO 5807)

YesNoStartInput a, keyc = 0x in ax == keyc++Return cEndFigure 1 — P.count

Source code

class P {
    static int count(int[] a, int key) {
        int c = 0;
        for (int x : a) {
            if (x == key) c++;
        }
        return c;
    }
}