LCM PROGRAME
previous NextExample
import java.util.Scanner;
class Raj
{
public static void main(String[] args) {
int a,b;
int big,small;
Scanner sc = new Scanner(System.in);
System.out.println("Enter the value of a and b: ");
a = sc.nextInt();
b = sc.nextInt();
if(a>b)
{
big = a;
small = b;
}
else {
big = b;
small = a;
}
for(int i =1; i<=big;i++)
{
if(((big*i)%small)==0)
{
int lcm = big*i;
System.out.println("The LCM is "+(lcm));
break;
}
}
}
}
Output :
Enter the value of a and b: 12 15 The LCM is 60