We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 8d3dcaf commit bd997cbCopy full SHA for bd997cb
challenge21.java
@@ -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
+}
AltStyle によって変換されたページ (->オリジナル) / アドレス: モード: デフォルト 音声ブラウザ ルビ付き 配色反転 文字拡大 モバイル
0 commit comments