print the LCM of the digits of the number java
Answers
Answered by
0
Least Common Multiplier or LCM of any n numbers is the least value that is a multiple of the given numbers.
For example:
Let us take three numbers such as 12, 15 and 18.
12 = 2 * 2 * 3
15 = 3 * 5
18 = 2 * 3 * 3
So we take the common prime factors and then the rest of the ones and multiply them with each other which would give us the LCM.
LCM = 2 * 2 * 3 * 3 * 5 = 180
Java program LCM of two numbers
pls mark as brilliant
Answered by
2
Answer:
{ public static void main(String args[])
{ long n1,n2,i=2,lcm,b;
n1=Long. parseLong(args[0]); n2=Long. parseLong(args[1]);
if(n1>n2) lcm=n1;
else. lcm=n2;
b=lcm; while(lcm%n1!=0 || lcm%n2!=0)
{ lcm=b*i;
i++; }
Explanation:
hope its help
Similar questions