Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit bd997cb

Browse files
🍵
1 parent 8d3dcaf commit bd997cb

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

‎challenge21.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import java.util.Scanner;
2+
3+
// Create a program to find the Greatest Common Divisor (GCD) of two integers.🚀
4+
public class challenge21 {
5+
public static void main(String[] args) {
6+
Scanner sc = new Scanner(System.in);
7+
System.out.println("Welcome to GCD!");
8+
System.out.print("Enter the first number: ");
9+
int num1 = sc.nextInt();
10+
System.out.print("Enter the second number: ");
11+
int num2 = sc.nextInt();
12+
int gcd = gcd(num1, num2);
13+
System.out.println("The GCD of " + num1 + " and " + num2 + " is: " + gcd);
14+
}
15+
16+
public static int gcd(int num1, int num2) {
17+
if (num2 == 0) {
18+
return num1;
19+
}
20+
return gcd(num2, num1 % num2);
21+
}
22+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /