Notice
Recent Posts
Recent Comments
Link
«   2026/04   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30
Tags
more
Archives
Today
Total
관리 메뉴

우당탕탕 개발자 되기

JAVA - 최대공약수, 최소공배수 본문

JAVA

JAVA - 최대공약수, 최소공배수

KimMINHun 2021. 1. 30. 20:32
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();

		System.out.println(Gcd(a, b));
		System.out.println(Lcd(a, b));

	}

	public static int Gcd(int a, int b) {
		if (b == 0)
			return a;
		else
			return Gcd(b, a % b);
	}

	public static int Lcd(int a, int b) {
		int g = Gcd(a, b);

		return g * (a / g) * (b / g);
	}

}

'JAVA' 카테고리의 다른 글

접근 제어자  (0) 2021.12.15
Comparable<T> vs Comparator<T>  (0) 2021.07.23
Iterator & ListIterator  (0) 2021.02.25
DFS(깊이우선탐색) 알고리즘  (0) 2021.01.31
JAVA 공부  (0) 2021.01.18