hi, i have seen ur post of gpf, just have a few ques. is the following approach ok: first find all the factors, then test which of the factors r prime, and then find the largest of those factors??

hope to hear from you soon.

Printable View

- 07-23-2010, 01:29 PMjava_prgrgreatest prime factor
hi, i have seen ur post of gpf, just have a few ques. is the following approach ok: first find all the factors, then test which of the factors r prime, and then find the largest of those factors??

hope to hear from you soon. - 07-23-2010, 04:23 PMJosAH
- 07-23-2010, 08:28 PMjava_prgr
i have found all the prime factors. r u saying that the last prime factor will be the largest prime factor? my code is:

import java.util.Scanner;

public class GPF {

public static void main(String[] srgs) {

Scanner keyboard = new Scanner(System.in);

int num,prifac,count=0;

System.out.print("Enter a number: ");

num = keyboard.nextInt();

for(int i=1;i<num;i++){

if(num%i == 0){

for(prifac=2;prifac<i;prifac++){

if(i%prifac == 0){

count++;

}

}

if(count<=0){

System.out.print(i+"\t");

}

count =0;

}

}

}

}

wat shud i add to ensure that the last prime factor is the largest and shud be printed?

thnx