answersLogoWhite

0


Best Answer

Factoring numbers into prime numbers, as taught in school, is much too complicated to program. To write a simple computer program, I would use the formula:

a x b = lcm(a, b) x gcd(a, d)

In other words, lcm(a, b) = a x b / gcf(a, d).

The greatest common factor can be found easily with Euclid's Formula. For example, to calculate the greatest common factor of 14 and 10:

gcf(14, 10) is the same as gcf(10, 4), where 4 is calculated as 14 % 10.

gcf(10, 4) is the same as gcf(4, 2). Again, 2 is calculated as 10 % 4.

Once you get a remainder of zero, stop. In this case, 4 % 2 = 0, so 2 is the gcf. In this case, the lcm can be calculated as 14 * 10 / 2.

User Avatar

Wiki User

11y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

12y ago

private int calculateLCM(int input[]) {

int LCM = input[0], tempCount = 0,tempVal = 0,num = 0;

try {

for (int i = 1; i < input.length; i++) {

LCM = Math.max(LCM, input[i]);

num = Math.min(LCM, input[i]);

tempVal = LCM;

tempCount = 2;

while ((tempVal % num) != 0) {

tempVal = LCM * tempCount;

tempCount++;

}

LCM = tempVal;

}

} catch (Exception e) {

e.printStackTrace();

}

return LCM;

}

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is the Logic of LCM for java programs?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the kinds of java programs?

the two types of java programs are Applet and application programs


Small Java-based programs are called?

Java applets


Does java script coding mean using it for Java programs only?

Java script coding is computer coding, many things require Java, and you need to have Java enabled to view these types of programs.


What are the uses of java database connectivity?

Java Database Connectivity, a Java API that enables Java programs to execute SQL statements. This allows Java programs to interact with any SQL-compliant database.


Do you have to have java on your coumpter to run everything on your coumpter?

No; lots of programs run without Java. You only need the Java runtime to run programs specifically designed with Java technology.


Difference between java applets from java application?

Java applets are programs which we can embed in a webpage. It will act from server to client machine. But java can be used to make stand alone programs also. These programs will include games, freewares and all.


What is the providence of US?

The JRE refers to Java Runtime Environment... JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Without the JRE we cannot execute our Java programs.


What is business logic and presentation logic in java?

business logic ....refers to the domain specific logic rules,proc,and processes presentation logic......concerned with how objects are displayed to the user of the software


What is the best compiler can be used to create Java programs?

A Java compiler.


What is the use of providing jre?

The JRE refers to Java Runtime Environment... JRE is an implementation of the Java Virtual Machine which actually executes Java programs. Without the JRE we cannot execute our Java programs.


Does java charge you monthly?

Java itself is freely distributed. You may have to pay for programs written in Java, however.


Which package in java is treated as default package?

java.lang defines the core Java language, without which all of Java would fail to operate. It is therefore the default package that must be used with every program that will run Java, as it contains all of the logic necessary for exception handling, threads, classes that represent primitives (and their associated logic), and so on.