-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstat.java
More file actions
33 lines (28 loc) · 958 Bytes
/
Copy pathstat.java
File metadata and controls
33 lines (28 loc) · 958 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
import java.util.Scanner;
public class stat {
public static void main(String[] args) {
// Use Scanner to take user input
Scanner scanner = new Scanner(System.in);
int num1 = scanner.nextInt();
int num2 = scanner.nextInt();
// Find the GCD using the Euclidean algorithm
int gcd = findGCD(num1, num2);
// Print the GCD
System.out.println("The GCD of " + num1 + " and " + num2 + " is " + gcd + ".");
scanner.close();
}
// Method to find the GCD using the Euclidean algorithm
public static int findGCD(int a, int b) {
//write your code here
while(b>0) {
int rem = a % b;
if (rem == 0 ) {
System.out.println("The GCD of " + a + " and " + b + " is " + b );
} else {
a = b;
b = rem;
}
}
return a;
}
}