I'm making a Fraction calculator and i've gotten to the point where i can solve it to it's final answer, the only problem i'm stumped on is how to simplify the final answer. plz help
I'm making a Fraction calculator and i've gotten to the point where i can solve it to it's final answer, the only problem i'm stumped on is how to simplify the final answer. plz help
lookup how modulo works, you'll need to find remainders here.
divide the fraction each number of the fraction by the denominator.. if the denominator yields a non integer # then its no good
Last edited by nox; 11-03-2009 at 07:34 PM.
find the least common factors of the denominator and numerator and just cancel like terms... unless i'm missing the point do you have like Integer1/Integer2 ?
uhmm
create a new class
and you're gonna have to do it contructor style like how ure last thread was...
and try this
Code:private void Reduce(){ int a = numerator; int b = denominator; int c = 0; while( b!= 0 ) { c = a % b; a = b; b = c; } denominator/=a; numerator/=a; }
i did this last week in my comp sci class.
We Gettin' -بجدية Money!
wtf is this shit
Code:package reduce; public class Reduce { private int numerator; private int denominator; public static void main (String[] args) { Reduce(2, 4); // example call } public void Reduce(int numerator, int denominator) { int numerator = this.numerator; int denominator = this.denominator; int c = 0; while( b != 0 ) { c = numerator % denominator; numerator = denominator; denominator = c; } denominator/=a; numerator/=a; System.out.print(numerator + "\n" + denominator); } }
lol mx. basically the same thing broe...
i had it so he'd have to create another class cause in hte OP he said he got everything down but the reducing...
so when it was done evaluating what ever code he did have he'd just have to put
Reduce(numerator,denominator);
in his main class, without him havin to change up or move his code around
We Gettin' -بجدية Money!
Great post! It's very nice and userful. Thank you so much for Paul post.
Bookmarks