Results 1 to 11 of 11

# Thread: please help

- 11-04-2008, 06:39 PM #1Member
- Join Date
- Oct 2008
- Posts
- 5

- Rep Power
- 0

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

- 11-04-2008, 06:53 PM #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.

- 11-04-2008, 11:52 PM #3Member
- 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.

- 11-04-2008, 11:56 PM #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

- 11-05-2008, 12:08 AM #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

- 11-05-2008, 12:16 AM #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**Chris S.**

**Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.**

- 11-06-2008, 01:01 AM #7Member
- 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);

}

- 11-06-2008, 03:54 AM #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**Chris S.**

**Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.**

- 11-06-2008, 07:08 PM #9Member
- Join Date
- Oct 2008
- Posts
- 5

- Rep Power
- 0

so that isnt how to start it?

- 11-06-2008, 09:59 PM #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**Chris S.**

**Difficult? This is Mission Impossible, not Mission Difficult. Difficult should be easy.**

- 11-07-2008, 07:13 AM #11
- Join Date
- Jul 2007
- Location
- Colombo, Sri Lanka
- Posts
- 11,371
- Blog Entries
- 1

- Rep Power
- 20

Are you want to get two integer values from the user or you want to generate them randomly?

## Bookmarks