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
29 lines (23 loc) · 844 Bytes
/
Copy pathGCD.java
File metadata and controls
29 lines (23 loc) · 844 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
/**
* Java program to find Greatest Common Divisor or GCD of
* two numbers using Euclid’s method.*/
importjava.util.*;
publicclassGCD{
publicstaticvoidmain(Stringargs[]){
//Enter two number whose GCD needs to be calculated.
Scannersc = newScanner(System.in);
System.out.println("Please enter first number to find GCD");
intnum1 = sc.nextInt();
System.out.println("Please enter second number to find GCD");
intnum2 = sc.nextInt();
System.out.println("GCD of two numbers " + num1 +" and "
+ num2 +" is :" + GCD(num1,num2));
}
privatestaticintGCD(intnum1, intnum2) {
//base case
if(num2 == 0){
returnnum1;
}
returnGCD(num2, num1%num2);
}
}