I am writing a program to find perfect numbers. The first step in doing this is to find all of the factors of a number. I need some code to find the factor of a number and save the factors to an array (NOT print the numbers). This is what I have so far, but it returns a NullPointerException:
public static int[] getFactors(int number) {
int factorNumber = 1;
int varArrayStoreID = 0;
int[] factors = null;
while(factorNumber <= number){
if(number % factorNumber == 0){
varArrayStoreID = varArrayStoreID + 1;
factors[varArrayStoreID] = factorNumber;
}
factorNumber++;
}
return factors;
}
Thanks.