public class RectangleDos{ public static int num; public static int den; public double val; public void display(){ System.out.println("FRACTION: " + num + "/" + den); } public int GCD(int a, int b) { while (a != 0 && b != 0) { if (a > b) a %= b; else b %= a; } if (a == 0) return b; else return a; } public double doubleValue(){ val = num * 1.0 / den * 1.0; return val; } public static void main(String[] args) { int u; RectangleDos x = new RectangleDos(); x.num =77; x.den =11; x.display(); System.out.println("DOUBLEVALUE: " + x.doubleValue()); System.out.println(x.GCD(num, den)); } }
I already solved my first problem on how to find the GCD. Now I need to make a new function which is Simplify(), wherein it will give the lowest term of the numerator and the denominator. I already got the GCD, so how do I throw in that value to the Simplify function to divide the numbers?