Skip to content

Commit 9c81ec7

Browse files
authored
Added gcd in Java
1 parent 9371ea2 commit 9c81ec7

File tree

1 file changed

+17
-0
lines changed

1 file changed

+17
-0
lines changed

Gcd.java

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Test {
2+
3+
static int gcd(int a, int b)
4+
{
5+
if (b == 0)
6+
return a;
7+
return gcd(b, a % b);
8+
}
9+
10+
// Driver method
11+
public static void main(String[] args)
12+
{
13+
Scanner sc=new Scanner(System.in);
14+
int a=sc.nextInt(),b=sc.nextInt();
15+
System.out.println("GCD of " + a +" and " + b + " is " + gcd(a, b));
16+
}
17+
}

0 commit comments

Comments
 (0)