Results 1 to 3 of 3
  1. #1
    java_prgr is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default 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. #2
    JosAH's Avatar
    JosAH is online now Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,371
    Blog Entries
    7
    Rep Power
    20

    Default

    Quote Originally Posted by java_prgr View Post
    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. #3
    java_prgr is offline Member
    Join Date
    Jul 2010
    Posts
    6
    Rep Power
    0

    Default

    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

Similar Threads

  1. Finding Largest Prime Factor
    By perito in forum New To Java
    Replies: 7
    Last Post: 11-08-2010, 08:25 PM
  2. Returning the Greatest Prime Factor
    By BJ1110 in forum New To Java
    Replies: 15
    Last Post: 10-23-2009, 10:06 PM
  3. Prime Number - System print all the prime numbers ...
    By pinkdreammsss in forum New To Java
    Replies: 20
    Last Post: 04-26-2009, 01:50 AM
  4. find the greatest and lowest number in 2D array
    By le_albina@hotmail.com in forum New To Java
    Replies: 2
    Last Post: 03-30-2009, 11:09 PM
  5. Prime numbers
    By gapper in forum New To Java
    Replies: 3
    Last Post: 02-07-2008, 10:09 AM

Posting Permissions

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