package Group3;
import java.util.Arrays;
public class Test1 {
public static void main(String[] args) {
int[] nums = {7, 5, 6, 8, 3};
Test1 test1 = new Test1();
int gcd = test1.findGCD(nums);
System.out.println(gcd);
}
public int findGCD(int[] nums) {
Arrays.sort(nums);
int min=nums[0];
int max=nums[nums.length-1];
return getGCD(min,max);
}
private int getGCD(int min, int max) {
if(max == min) {
return min;
}
while(min != 0) {
int tmp = max % min;
max = min;
min = tmp;
}
return max;
}
}
碾转相除法 求公约数
最新推荐文章于 2022-08-18 15:35:13 发布