-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGcd.java
More file actions
31 lines (27 loc) · 793 Bytes
/
Gcd.java
File metadata and controls
31 lines (27 loc) · 793 Bytes
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
31
import java.util.*;
class Gcd {
public static int maximum(int num1, int num2){
if (num1 > num2) {
return num1;
}
else{
return num2;
}
}
public static void gdc(int num1, int num2, int max){
int gcd = 0 ;
for(int i = 1; i <= max; i++){
if(num1 % i == 0 && num2 % i == 0){
gcd = i;
}
}
System.out.println("The greatest common divisor of "+num1 +"and "+num2+ " is "+ gcd);
}
public static void main(String[] args) {
Scanner num = new Scanner(System.in) ;
int n1 = num.nextInt();
int n2 = num.nextInt();
int max = maximum(n1, n2);
gdc(n1, n2, max);
}
}