9. Program
9. Find the LCM of 3 Number ?
like input is 3 4 5 then output will be 60
import java.util.Scanner;
class Lcm
{ static int i=0, flag = 0;
private static int lcm(int a, int b, int c){
if(a==0 || b==0 || c==0 )
{
System.out.println("Error Message : Number must be greater then 0");
return 0;
}
while( flag == 0)
{
i++;
if(i%a == 0 && i%b == 0 && i%c == 0)
{
flag = 1;
}
}
return i;
}
public static void main(String args[])
{
Scanner sc = new Scanner(System.in);
System.out.println("Enter first Number : ");
int x = sc.nextInt();
System.out.println("Enter second Number : ");
int y = sc.nextInt();
System.out.println("Enter third Number : ");
int z = sc.nextInt();
System.out.println("LCM of "+x+", "+y+" & "+z+" is : "+lcm(x,y,z));
}
}