Skip to content

Instantly share code, notes, and snippets.

@panwarab
Created September 16, 2018 12:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save panwarab/dc526e25c7111e83a2dbf56e058a20c2 to your computer and use it in GitHub Desktop.
Save panwarab/dc526e25c7111e83a2dbf56e058a20c2 to your computer and use it in GitHub Desktop.
import java.util.Scanner;
public class LCM {
public static void main(String[] args) {
Scanner sc=new Scanner(System.in);
int a=sc.nextInt();
int b=sc.nextInt();
int hcf=gcd(a,b);
int lcm=(a*b)/hcf;
System.out.println("LCM is "+lcm);
}
private static int gcd(int a, int b) {
if(a==0) return b;
return gcd(b%a,a);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment