FIND GCD AND LCM OF TWO INTEGER

This is the Program to find the GCD and LCM of two Integers

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
import java.util.Scanner;
public class GcdLcm
{
    public static void main(String[] args)
    {
        int a,b;
        int gcd, lcm, remainder, numerator, denominator;
         System.out.println("Enter the two numbers");
         Scanner in = new Scanner(System.in);
         a = in.nextInt();
         b=in.nextInt();
         if (a > b)
         {
            numerator = a;
            denominator =b;
         }
         else
         {
            numerator = b;
            denominator = a;
        }
            remainder = a % b;
         while(remainder !=0)
         {
            numerator   = denominator;
            denominator = remainder;
            remainder   = numerator % denominator;
         }
         gcd = denominator;
         lcm =a * b / gcd;
         System.out.println("GCD"+gcd);
         System.out.println("LCM"+lcm);
    }
}

Output :GCD and LCM

addm