Computer Science, asked by moulikrajdeep, 7 months ago

WAP using method name Glam (int, int) to find the LCM of two no.s by G.C.D of the no.s. GCD of two nos is calculated by continued division method. Divide the largest no bythe smaller, the remainder then divides the previous divisior. The process is repeated till the remainder is zero. The divisor then results in the GCD. LCM=puoduct of two no.s/GCD

Answers

Answered by anidivi2803
3

Answer:

Explanation:

import java.util.Scanner;

public class LCM {

   public static void main(String[] args) {

       Scanner scan = new Scanner(System.in);  //for input

       System.out.println("Enter any 2 integers :");

       int a = scan.nextInt();  //input 1

       int b = scan.nextInt();  //input 2

       glam(a, b);  // call method glam

   }

   public static void glam(int x, int y) {

       if (x > y) { // to find bigger integer

           findLCM(x, y);

       } else if (y > x) {

           findLCM(y, x);

       } else if (x == y) {

           System.out.println("The LCM is : " + x);

       }

   }

   public static void findLCM(int x, int y){

           int de, di, r;

           de = y;

           di = x;

           r = di % de;

           while (r!=0){

               di = de; //to repeat the process to finding GCD

               de = r;// to repeat the process to finding GCD

               r = di % de;

           }

           System.out.println("The LCM is : "+ x * y / de);

   }

}

This is the code in java....

hope you find it helpful :)

Similar questions