forked from Annex5061/java-algorithms
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGcd.java
More file actions
Latest commit
33 lines (29 loc) · 687 Bytes
/
Copy pathGcd.java
File metadata and controls
33 lines (29 loc) · 687 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
32
33
importjava.util.*;
classGcd
{
publicstaticintgcd(intn1,intn2)
{
while(n1!=n2)
{
if(n1>n2)
{
n1=n1-n2;
}
else
{
n2=n2-n1;
}
}
returnn1;
}
publicstaticvoidmain(Stringargs[])
{
intn1,n2;
ScannerSc = newScanner(System.in);
System.out.print("enter n1:");
n1=Sc.nextInt();
System.out.print("enter n2:");
n2=Sc.nextInt();
System.out.println("gcd of "+n1+" and "+n2+" is "+gcd(n1,n2));
}
}