Guest User

Untitled

a guest
Apr 22nd, 2018
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.38 KB | None | 0 0
  1. package fractions;
  2.  
  3. public class Fraction {
  4.  
  5. private int numerator;
  6. private int denominator;
  7.  
  8. public Fraction(int n, int d) throws ArithmeticException {
  9.  
  10. if (d == 0) {
  11. throw new ArithmeticException("denominator is zero");
  12. }
  13. else if (n==0) {
  14. d = 1;
  15. n = 0;
  16. }
  17. else if (d<0 ) {
  18. n = -n;
  19. d = -d;
  20. }
  21. else{
  22. gcd(n, d);
  23. }
  24.  
  25.  
  26. }
Add Comment
Please, Sign In to add comment