// Collection of code snippets by Arne Vajhøj 
// (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) 
public class Even {
    public static int[] cutoutEven1(int[] a) {
        int n = 0;
        int[] b = new int[a.length];
        for(int i = 0; i < a.length; i++) {
            if(a[i] % 2 == 0) {
                b[n] = a[i];
                n++;
            }
        }
        int[] c = new int[n];
        System.arraycopy(b, 0, c, 0, n);
        return c;
    }
    public static int[] cutoutEven2(int[] a) {
        int n = 0;
        for(int i = 0; i < a.length; i++) {
            if(a[i] % 2 == 0) {
                n++;
            }
        }
        int[] c = new int[n];
        int ix = 0;
        for(int i = 0; i < a.length; i++) {
            if(a[i] % 2 == 0) {
                c[ix] = a[i];
                ix++;
            }
        }
        return c;
    }
    public static void main(String[] args) {
        int[] a = { 1, 2, 3, 5, 7, 8, 10, 12};
        int[] res1 = cutoutEven1(a);
        for(int i = 0; i < res1.length; i++) {
            System.out.println(res1[i]);
        }
        int[] res2 = cutoutEven2(a);
        for(int i = 0; i < res1.length; i++) {
            System.out.println(res2[i]);
        }
    }
}
