-
Notifications
You must be signed in to change notification settings - Fork 2
/
GCD.java
50 lines (50 loc) · 985 Bytes
/
GCD.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import java.util.*;
class GCD
{
public static void main(String[] args)
{
Scanner obj = new Sacanner(System.in);
GCD in = new GCD(System.in);
int A,B;
System.out.println("Enter the number for GCD \n");
System.out.println("A : ");
A = obj.nextInt();
System.out.println("B : ");
A = obj.nextInt();
in.operation(A,B);
}
public static int operation(int a,int b)
{
int remainder =0,division =0;
boolean finalEnd = True;
while(finalEnd)
{
division = a/b;
remainder = a%b;
if(a == ((b*division)+remainder))
{
a = b;
b = remainder;
}
else if(a==0||b==0)
{
in.finalGCD(a,b);
finalEnd = False;
}
}
}
public static void finalGCD(int a,int b)
{
if (a==0||b==0)
{
if (a==0)
{
System.out.println("GCD is :"+a);
}
else
{
System.out.println("GCD is :"+b);
}
}
}
}