I make a class to make Arithmetic operations on rational numbers the problem is when I run the program it keeps running and never stops or show results after many tries I discovered that the problem is the reduce method it is just stuck and never completed . any ideas ?
private void normalize() {
if ( (this.num > 0 && this.den < 0) || (this.num < 0 && this.den < 0)){
this.num = -this.num;
this.den = -this.den;
}
}
private void reduce(int n , int d) {
int r , L = 0;
while ( (n!=0) && (d!=0) ) {
if (this.den > this.num)
r = den % num ;
else
r = num % den ;
while (r != 0 ){
for ( int i= r ; i>0 ; i-- ){
if (den % i == 0 && num % i == 0 )
L = i ;
}
num = num / L ;
den = den / L ;
}
}
}
public Rational (int num , int den) {
this.num = num ;
this.den = den ;
normalize();
reduce (this.num , this.den) ;
}