Computer Science AP - Classes - Private Helper Methods

Опубликовано: 17 Июнь 2026
на канале: mistapotta
1,373
2

In this video, we create a private helper function (GCD) and a parameterless mutator (reduce) to complete the work on our Fraction class.

=-=

Blackbox code - GCD Method


private int gcd(int a, int b)


{


int big = Math.max(a, b);


int small = Math.min(a,b);


while ( big % small != 0)


{


//Chinese Remainder Theorem


int diff = big - small;


big = Math.max(diff, small);


small = Math.min(diff, small);



}


return small;


}