1. Member
Join Date
Oct 2008
Posts
5
Rep Power
0

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.

2. 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. Member
Join Date
Oct 2008
Posts
5
Rep Power
0
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. 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. 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. ## 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

7. Member
Join Date
Oct 2008
Posts
5
Rep Power
0

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

9. Member
Join Date
Oct 2008
Posts
5
Rep Power
0
so that isnt how to start it?

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

#### Posting Permissions

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