The program should print the factors of a number which are prime.
One way of writing this is
import java.util.Scanner;
class PrimeFactors{
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;
}
}
}
public static void main(String args[]){
PrimeFactors pf = new PrimeFactors();
int n;
Scanner scanner = new Scanner(System.in);
n = scanner.nextInt();
pf.printFactors(n);
}
}