FactorCheck.java

less than 1 minute read

This program was created in order to check if the numbers of an array are factors of said number. If not, return false.

The code has been modified slightly and now uploaded to the site.

<— Return Home

Code Snippet

/*
Author: ENTPRESTIGIOUS
*/
    
import java.util.Arrays;
public class FactorCheck {
    public static void main(String[] args){
        int[] arr1 = {2, 3, 4};
        boolean result = CheckFactors(arr1, 12);
        int[] arr2 = {1, 2, 3, 8};
        boolean result2 = CheckFactors(arr2, 12);
        int[] arr3 = {1, 2, 50};
        boolean result3 = CheckFactors(arr3, 100);
        int[] arr4 = {3, 6};
        boolean result4 = CheckFactors(arr4, 9);
        System.out.println(result);
        System.out.println(result2);
        System.out.println(result3);
        System.out.println(result4);
    }
    public static boolean CheckFactors(int[] factors, int num){
        for (int i = 0; i < factors.length; i++){
            if (num % factors[i] != 0){
                return false;
            }
        }
        return true;
    }
}

<— Return Home