stuck in solving problem, questions involving array.:
Q1- listing divisibles of a number and putting it in array, like 40--->>2 4 5 8 10 20,, solved that and post it it may help another newbie.
Q2-continue and dont pass to another number as long as it is divisible, like 40---->> 2 2 2 5, i mean like continue to divide the number first divisible as long as it modulus is 0; it may needs inner loop, but couldnt fix it. any help?
//This works perfectly and may help others
public int [] findDivisibles(int num){
int arr []=new int[num];//link to input;
int i=2;
while(i<arr.length){
if(num%i==0){
arr=i;
System.out.print(arr[i]+" " );
}i++;
}return arr;
}
//problem is next, method
public int [] continiousDiv(int num){
int divisor [] = new int [num];
int i=2; int k=1;
while(i<=divisor.length-1){
if((num%i==0)){
divisor[i]=i;
int res = num/divisor[i]; //after division
System.out.print(" round ="+i +" , after division ="+res);//
if(res%divisor[i]==0){ // if res is still divisible
divisor=continiousDiv(res); // repeat it
}
}i++;
}
return divisor;
}
there are no errors, but i couldnt sort out stopping it when it reaches like 40 = 2*2*2*5, instead it will go all the numbers as first method