Prime Factors of a given number
The program should print the factors of a number which are prime.
One way of writing this is
void printFactors(int num){
if(num%2==0){
System.out.println("2 ");
while (num%2==0)
num = num/2;
}
for(int i=3;i<=num;i+=2){
if(num%i==0){
System.out.println(i);
while(num%i==0)
num = num/i;
}
}
}