-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathchallenge21.java
More file actions
22 lines (20 loc) · 817 Bytes
/
challenge21.java
File metadata and controls
22 lines (20 loc) · 817 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import java.util.Scanner;
// Create a program to find the Greatest Common Divisor (GCD) of two integers.🚀
public class challenge21 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to GCD!");
System.out.print("Enter the first number: ");
int num1 = sc.nextInt();
System.out.print("Enter the second number: ");
int num2 = sc.nextInt();
int gcd = gcd(num1, num2);
System.out.println("The GCD of " + num1 + " and " + num2 + " is: " + gcd);
}
public static int gcd(int num1, int num2) {
if (num2 == 0) {
return num1;
}
return gcd(num2, num1 % num2);
}
}