package k20231205;

import java.util.Scanner;
public class EuclideanAlgorithm2 {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
System.out.print("숫자 2개를 입력하세요: ");
int a = scanner.nextInt();
int b = scanner.nextInt();
int r = 1;
int high;
int low;
if (a>=b) {
high=a;
low=b;
} else {
low=a;
high=b;
}
System.out.printf("큰 수: %d, 작은 수 : %d\n", high, low);
while (r>0) {
r = high%low;
high = low;
low = r;
}
int l = a*b/high;
// 최대공약수, 최소공배수를 출력한다.
System.out.printf("최대공약수: %d, 최소공배수: %d\n", high, l);
}
}
'java&eclipse 코딩 알고리즘 > 20231205' 카테고리의 다른 글
| MenuTest2 (0) | 2023.12.14 |
|---|---|
| MenuTest (0) | 2023.12.14 |
| EuclideanAlgorithm (0) | 2023.12.14 |
| ConvertTest4 Self (0) | 2023.12.14 |
| ConvertTest3 (0) | 2023.12.14 |