Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.

>> REGISTER NOW TO START POSTING

# Thread: Lowest Term Function Help

1. ## Lowest Term Function Help

```public class RectangleDos{

public static int num;
public static int den;
public double val;

public void display(){
System.out.println("FRACTION: " + num + "/" + den);
}

public int GCD(int a, int b)
{
while (a != 0 && b != 0)
{
if (a > b)
a %= b;
else
b %= a;
}

if (a == 0)
return b;
else
return a;
}

public double doubleValue(){
val = num * 1.0 / den * 1.0;
return val;
}

public static void main(String[] args) {
int u;
RectangleDos x = new RectangleDos();
x.num =77;
x.den =11;

x.display();

System.out.println("DOUBLEVALUE: " + x.doubleValue());

System.out.println(x.GCD(num, den));

}
}```

I already solved my first problem on how to find the GCD. Now I need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator. I already got the GCD, so how do I throw in that value to the Simplify function to divide the numbers?

2. ## Re: Lowest Term Function Help

Originally Posted by thisbeme
Care to help?
I can't decide whether I can help without spoonfeeding or not.
This is what you're trying to do: Greatest common divisor - Wikipedia, the free encyclopedia
You have to write Euclid's algorithm at least once yourself before you use the method in BigInteger - it's a rite of passage thing.

3. ## Re: Lowest Term Function Help

Originally Posted by Sean4u
I can't decide whether I can help without spoonfeeding or not.
This is what you're trying to do: Greatest common divisor - Wikipedia, the free encyclopedia
You have to write Euclid's algorithm at least once yourself before you use the method in BigInteger - it's a rite of passage thing.
im sorry i was to lazy to search about it. well anyways thanks about that euclid's algorith thing, i tried to search it and somehow i got how it works. thanks again.

but i still have a problem with my code. hope you can help me

4. ## Re: Lowest Term Function Help

still have a problem with my code
Does it compile?
Does it execute?
Does it generate output? Is the output correct? If not, explain what is wrong with it and what it should be.

5. ## Re: Lowest Term Function Help

Originally Posted by Norm
Does it compile?
Does it execute?
Does it generate output? Is the output correct? If not, explain what is wrong with it and what it should be.
yes it execute and compile but...

I still need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator. I already got the GCD, so how do I throw in that value of the GCD to the Simplify function to divide the numbers?

Hope you can help me. thanks in advance

6. ## Re: Lowest Term Function Help

I still need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator.
Do you have the algorithm for finding them?