So, i`m now fifth grande and i am learning about Biggest General Divisor. And i really struggled to understand how to do it, but at the last moment i understood. And this idea poped into my head: "What if i just make a program on Java which finds me Biggest General Divisor?". So i got on my computer and started programming. After a few days i was ready an so did the program. But the problem was that it could calculate with only two numbers. Anyways, the code is below if anyone wants to use it...
/** * Find Biggest General Divisor * @param num1 * @param num2 * @return */ public float FBGD(int num1, int num2) { ArrayList<Float> NG1 = new ArrayList<>(); ArrayList<Float> NG2 = new ArrayList<>(); ArrayList<Float> Divisors = new ArrayList<>(); for (int i = 1; i <= num1; i++) { float x = num1; x = x / i; if (x % 1 == 0) { NG1.add(x); } } for (int j = 1; j <= num2; j++) { float y = num2; y = y / j; if (y % 1 == 0) { NG2.add(y); } } for (int a = 0; a <= NG1.size() - 1; a++) { float curNum1 = NG1.get(a); for (int b = 0; b <= NG2.size() - 1; b++) { float curNum2 = NG2.get(b); if (curNum1 == curNum2) { Divisors.add(curNum1); } } } Divisors.sort(Comparator.naturalOrder()); float numDiv = Divisors.size() - 1; float maxDiv = Divisors.get((int) numDiv); return maxDiv; }