Now i`ve advanced the program and you can now Find the Biggest General Divisor with three numbers. The code is below if eanyone needs it.
/** * Find Biggest General Divisor * @param num1 * @param num2 * @param num3 * @return */ public float FBGD(int num1, int num2, int num3) { ArrayList<Float> NG1 = new ArrayList<>(); ArrayList<Float> NG2 = new ArrayList<>(); ArrayList<Float> NG3 = 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 k = 1; k <= num3; k++) { float z = num3; z = z / k; if (z % 1 == 0) { NG3.add(z); } } 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); for (int c = 0; c <= NG3.size() - 1; c++) { float curNum3 = NG3.get(c); if (curNum1 == curNum2 && curNum1 == curNum3 && curNum2 == curNum3) { Divisors.add(curNum1); } } } } Divisors.sort(Comparator.naturalOrder()); float numDiv = Divisors.size() - 1; float maxDiv = Divisors.get((int) numDiv); return maxDiv; }
Now, see, this is kind of the previous program that i made, but with some additions. To see the previous program click the link below.