Dain1234 / Java-Programming

0 stars 0 forks source link

Composite number in a array #5

Open Dain1234 opened 1 year ago

Dain1234 commented 1 year ago

package com.dain.logics;

public class compositenumbersinArray { public static void main(String[] args) { int a[] = { 16, 18, 27, 16, 23, 21, 19 }; int len = a.length; int count = 0;

    for (int i = 0; i < len; i++) {
        int c = 0;// inside an array counts factors
        for (int j = 1; j < 100; j++) {
            if (a[i] % j == 0) {
                c++;
            }
        }
        if (c > 2) {

            count++;
        }

    }
    System.out.println(count);

}

}