Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Fraction {
- int numerator, denominator;
- public Fraction(int nume, int denom) {
- numerator= nume;
- denominator= denom;
- }
- @Override
- public String toString() {
- return "Fraction [numerator=" + numerator + ", denominator=" + denominator + "]";
- }
- private static Fraction simplify(Fraction toSimplify) {
- int smallest;
- if (toSimplify.numerator < toSimplify.denominator) {
- smallest= toSimplify.numerator;
- } else
- smallest= toSimplify.denominator;
- int aux= smallest/2;
- boolean check= false;
- while (aux > 1 && !check) {
- if (toSimplify.numerator% aux == 0 && toSimplify.denominator% aux == 0) {
- check= true;
- }
- aux--;
- }
- if (check) {
- return new Fraction(toSimplify.numerator/(aux + 1), toSimplify.denominator/(aux + 1));
- } else {
- return toSimplify;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement