최대 공약수와 최소 공배수 2015-01-07 ProgrammingAlgorithm Algorithm, Programming 12345678910111213141516171819202122232425262728293031public class GCDLCM { public static void main(String[] args) { System.out.println(gcd(24, 18)); System.out.println(lcm(24, 18)); } public static int gcd(int a, int b) { int c = a % b; if (c == 0) { return b; } return gcd(b, c); } public static int lcm(int a, int b) { int m = a, n = b; int i = 1, j = 1; while (m != n) { if (m < n) { m = a * ++i; } else { n = b * ++j; } } return m; }} Newer 로마숫자 Older Java Iterator Pattern on Colletions