MCPcopy Create free account
hub / github.com/Manvityagi/PW-Skills-Java-Course-Codes / GCD

Class GCD

Lecture 31 - Recursion PS4 GCD/src/GCD.java:3–25  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1import java.util.Scanner;
2
3public class GCD {
4 static int gcd(int x, int y){
5 if(y == 0) return x;
6 return gcd(y, x % y);
7 }
8
9 static int iGCD(int x, int y){
10 while (x % y != 0){
11 int rem = x % y;
12 x = y;
13 y = rem;
14 }
15 return y;
16 }
17
18 public static void main(String[] args) {
19 Scanner sc = new Scanner(System.in);
20 int x = sc.nextInt();
21 int y = sc.nextInt();
22 System.out.println(iGCD(x, y));
23 System.out.println(gcd(x, y));
24 }
25}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected