after c++ i am trying to learn some java, and i have a question about the code i have been working on. I am working on a Fraction class and i got stuck in reduce section. Since the method did not let me to return both "num" and "den", I had to return "n" This is my method
public double reduce() {
int n = num;
int d = den;
while (d != 0) {
int t = d;
d = n % d;
n = t;
}
int gcd = n;
num /= gcd; //num = num / greatestCommonDivisor
den /= gcd; //den = den / greatestCommonDivisor
return n;
}
I am trying to do "return num, den;" however it does not let me.
and this is what i get
to reduced test for 100/2 is 2.0
to reduced test for 6/2 is 2.0
when i run
System.out.println("to reduced test for " + f4.toString() + " is " + f4.reduce());
System.out.println("to reduced test for " + f6.toString() + " is " +f6.reduce());
Why do i get the 2 when when i am supposed to get 50/1 and 3/1 ? If the IDE let me return num and den at the same time, would that have fixed it?
Thanks