Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public Rational add(Rational nTwo) {
- int redNum, redDen;
- int usrNumOne = this.num * nTwo.den;
- int usrDenOne = this.den * nTwo.den;
- int usrNumTwo = nTwo.num * this.den;
- int usrDenTwo = nTwo.den * this.den;
- redNum = usrNumOne + usrNumTwo;
- redDen = usrDenOne + usrDenTwo;
- int gcd = gcd(redNum, redDen);
- redNum /= gcd;
- redDen /= gcd;
- Rational added = new Rational(redNum, redDen);
- return added;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement