public class Fraction {
int numerator, denominator = 1;
Fraction(int n) { numerator = n; }
Fraction(int n, int d) { numerator = n; denominator = d; normalize(); }
public int getNumerator() { return numerator; }
public int getDenominator() { return denominator; } void normalize() { int g = gcd(numerator, denominator); numerator = numerator/g; denominator = denominator/g; } int gcd(int a, int b) { if (b == 0) return a; else return gcd(b, a%b); }
public String toString() { if (denominator != 1) { return numerator + "/" + denominator; } else { return "" + numerator; } }
}