public class GcdTest {

public static void main(String[] args) {

gcd(2, 5);

gcd(5, 15);

gcd(250, 30);

}


public static void gcd(int a, int b) {

int c;

if (a > b)

c = b;

else

c = a;

int i;

for (i = c; i >= 1; i--) {

if (a % i == 0 && b % i == 0)

break;

}

System.out.println("최대공약수 : " + i);

}

}

'Computer > JAVA' 카테고리의 다른 글

Java Properties  (0) 2014.08.29
Java PrimeNumber  (0) 2014.08.29
JDBC Null값 처리  (0) 2014.08.18
JDBC Date형 처리  (0) 2014.08.14
Java util.date sql.date 형변환  (1) 2014.08.14

+ Recent posts