Results 1 to 11 of 11

Thread: please help

  1. #1
    edgewater21 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default please help

    I am wondering how to do this.

    Implement a method static int gcd(int a, int b) to compute and return the greatest common divisor of a and b using the euclidean algorithm.

    In the main method, prompt the user to enter an integer n using a dialog box. Perform n trials of gcd calculations on random integers. In each trial, randomly generate a pair of positive integers a and b between 1 and 1000000. Count the total number of pairs with gcd(a,b)=1. Display the total count in a dialog box.

    Please help me.

  2. #2
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    show us some pseudocode of your algorithms and then make an attempt to code those and we can help you.

    You make the first effort and it's easier to get people to help you because nobody here will do your assignment for you.

  3. #3
    edgewater21 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default

    Im not any good at this. If I knew how to do it I wouldnt of posted on this forum. I know that isnt a good reason, but if there is any kinda soul out there that would to show me what to do I would greatly appreciate it.

  4. #4
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Try to implement the gcd method to start with. Make the method and call it from the main method of a test class. When you get that working you can go on to generating the random integers to use in calling the method. When that is working set up the user-input part.
    Here's a discussion if you can use it.
    Euclidean Algorithm

  5. #5
    xcallmejudasx's Avatar
    xcallmejudasx is offline Senior Member
    Join Date
    Oct 2008
    Location
    Houston, TX & Flint, MI
    Posts
    609
    Rep Power
    7

    Default

    O_O...That link melted my brain. That's what I get to look forward to when I take Differential Equations and Euclidean Algebra? ...Great

    Well show us at least an outline of how you plan to write the program. Do what hardwired said and show main, the methods you call within main, some variables you will use. Give us something to work with

  6. #6
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default Do it in parts...

    I'm assuming you know how to get the GCD on paper. So....
    • Stop says you're no good at this... you're not helping yourself with that way of thinking
    • Look at the steps that you have to do to get the GCD from two numbers. Write them down.
    • Turn those steps into some psuedo code.
    • You will have to implement those steps in your program (probably a good idea to implenment each step as a method).
    • Develop/code each method one at a time. Don't try to code everything at once (leads to dispear!).
    • I googled "java Euclidean Algorithm" and found: https://www.math.ubc.ca/~cass/euclid.pdf

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  7. #7
    edgewater21 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default i got this so far. thanks for the encouragement

    i need to have it submitted by tonight!!



    import javax.swing.JOptionPane;
    public class project9 {
    public static void main(String [] args)
    {
    String output= "Please enter an Integer ";
    String n1 = JOptionPane.showInputDialog(null, output);
    int n = Integer.parseInt(n1);
    JOptionPane.showMessageDialog(null, "Program is going to perform GCD : " + n +" Random Times");
    int a = 7;
    int b = 8;
    gcd(a,b);
    }
    public static void gcd(int a, int b){



    // gcd(a1,b1);
    }

  8. #8
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default really...

    You should read the suggestions that people give you. When I posted my previous post, I almost edited it because I practically gave you the answer. For some reason I didn't and from your answer, I see I don't have to.
    Luck,
    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  9. #9
    edgewater21 is offline Member
    Join Date
    Oct 2008
    Posts
    5
    Rep Power
    0

    Default

    so that isnt how to start it?

  10. #10
    CJSLMAN's Avatar
    CJSLMAN is offline Moderator
    Join Date
    Oct 2008
    Location
    Mexico
    Posts
    1,159
    Rep Power
    8

    Default It looks OK...

    I haven't run it so I don't know if it's working.
    • Have you run it?
    • Does it work?

    If you don't have any runnable code for the GCD method, you can temporarly use some dummy code like a println to check out what's in the main method.

    CJSL
    Chris S.
    Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.

  11. #11
    Eranga's Avatar
    Eranga is offline Moderator
    Join Date
    Jul 2007
    Location
    Colombo, Sri Lanka
    Posts
    11,371
    Blog Entries
    1
    Rep Power
    20

Posting Permissions

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