我的代码几乎完成了,但我必须弄清楚为什么我的“reduceToLowestTerms()”没有通过我的代码实现,并确保每次我输入一个分数时它都会这样做。
我的代码有点长,所以我将发布链接! https://gist.github.com/anonymous/0421493909708268ea9e
private void reduceToLowestTerms()
{
this.switchSign();
int i1 = greatestCommonDivisor(this.numerator, this.denominator);
this.numerator = this.numerator / i1;
this.denominator = this.denominator / i1;
} // end reduceToLowestTerms
private int greatestCommonDivisor(int integerOne, int integerTwo)
{
int result;
if (integerOne % integerTwo == 0)
result = integerTwo;
else
result = greatestCommonDivisor(integerTwo, integerOne % integerTwo);
return result;
}
这是由于某种原因没有在我的其余代码中实现的代码部分我如何确保我的所有分数都处于最低限度?