Created
September 16, 2018 12:31
-
-
Save panwarab/dc526e25c7111e83a2dbf56e058a20c2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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