I can get the prime factor of a number, but in the code,
static int[] factorsOf (int val) {
int index = 0;
int []numArray = new int[5];
System.out.println("\nThe factors of " + val + " are:");
for(int i=1; i <= val; i++)
{
if(val % i == 0)
{
numArray [index] = i;
val=val/i;
index++;
}
}
return numArray;
}
say a number is 21, so I get 1,3,7,0,0 because I decide the range of the array is 5, how can I erease the 0, make it becomes 1,3,7?