public class GCD {
public static int gcd(int a, int b) {
if (b == 0) {
return a;
} else {
return gcd(b, a % b);
}
}
public static int lcm(int a, int b) {
return (a * b) / gcd(a, b);
}
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
System.out.println("GCD: " + gcd(a, b));
System.out.println("LCM: " + lcm(a, b));
}
}
'자바' 카테고리의 다른 글
thread 활용방법 (0) | 2023.03.15 |
---|---|
배열 안에 특정 문자 규칙을 찾는 로직 (0) | 2023.03.15 |
문자열을 바이트단위로 자르기 (1) | 2023.01.10 |
[오류]Could not target platform: 'Java SE 11' using tool chain: 'JDK 8 (1.8)' in eclipse (0) | 2022.11.08 |
[TIFF FILE TO PDF] tiff 파일을 pdf로 변환 (1) | 2022.11.02 |