1. Member
Join Date
Jul 2010
Posts
6
Rep Power
0

## greatest 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.

2. Originally Posted by java_prgr
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.
Why not find prime factors only? Then the greatest factor you'll find will also be the greatest prime factor.

kind regards,

Jos

3. Member
Join Date
Jul 2010
Posts
6
Rep Power
0
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

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•