From daad675e888aa1892d696ca9c48678808a443238 Mon Sep 17 00:00:00 2001 From: Smriti Dube <140499593+smritii73@users.noreply.github.com> Date: Sun, 27 Oct 2024 14:02:49 +0530 Subject: [PATCH] Create Euclidgcd.java --- Euclidgcd.java | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 Euclidgcd.java diff --git a/Euclidgcd.java b/Euclidgcd.java new file mode 100644 index 000000000..b9be3c4b1 --- /dev/null +++ b/Euclidgcd.java @@ -0,0 +1,21 @@ +import java.util.Scanner; + +public class Euclidgcd { + \public static int gcd(int a, int b) { + while (b != 0) { + int temp = b; + b = a % b; + a = temp; + } + return a; + } + public static void main(String[] args) { + Scanner sc = new Scanner(System.in); + System.out.print("Enter the first number: "); + int a = sc.nextInt(); + System.out.print("Enter the second number: "); + int b = sc.nextInt(); + int result = gcd(a, b); + System.out.println("GCD of " + a + " and " + b + " is: " + result); + } +}