Advertisement
Guest User

Untitled

a guest
Jul 27th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. public Rational add(Rational nTwo) {
  2.  
  3. int redNum, redDen;
  4. int usrNumOne = this.num * nTwo.den;
  5. int usrDenOne = this.den * nTwo.den;
  6. int usrNumTwo = nTwo.num * this.den;
  7. int usrDenTwo = nTwo.den * this.den;
  8.  
  9. redNum = usrNumOne + usrNumTwo;
  10. redDen = usrDenOne + usrDenTwo;
  11.  
  12. int gcd = gcd(redNum, redDen);
  13.  
  14. redNum /= gcd;
  15. redDen /= gcd;
  16.  
  17. Rational added = new Rational(redNum, redDen);
  18.  
  19. return added;
  20.  
  21. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement