answersLogoWhite

0


Best Answer

These are the two functions you need:

public static int lcm(int i1, int i2) {

return (i1*i2/gcd(i1,i2));

}

public static int gcd(int i1, int i2) {

// using Euclid's algorithm

int a=i1, b=i2, temp;

while (b!=0) {

temp=b;

b=a%temp;

a=temp;

}

return a;

}

User Avatar

Wiki User

14y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Java program for finding GCD and LCM of two given numbers?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

Program for finding a minimum value in javaprogram for finding a minimum value in java?

program for finding a minimum value in javaprogram for finding a minimum value in java


Write a java program to find sum of even and odd numbers in given array?

for(int i = 1; i < 100; i+=2) { System.out.println(i); }


Program for finding the current workload of PC using java?

There is no way to do this in Java without using either JNI calls or executing an outside, platform-specific program.


How do you write a java program for finding multiligual languages?

You can use Java's built-in functions to write a code that will find multilingual languages.


What Program that will display the even numbers in data structures and algorithms?

JAVA


Is there a Java program for finding the zodiac sign?

I could make one, but "a program of zodiac signs" tells me little.


How to write a java program that determines the number of prime numbers less than N which is given by the user?

where to start? do you have an algorithm and just want to implement it in java? depends on how big N is, as that will determine which method is most efficient


How do you compile and execute a java program which finds out the highest of any five numbers?

it will be destroyed.


What do you mean by multithread program in java?

A Program in Java that spawns multiple threads is called a multithreaded program in Java.


What does it mean to generate random numbers in Java?

Generating random numbers in Java is somewhat of a misnomer because the numbers are actually semi-random.It means to use the program to obtain random integers to use in hypothetical situations such as statistics.


What is senf?

Senf is the German word for Mustard.It is also the name of a Java programming tool for finding numbers on computers (credit card numbers and the like).


Java program to find sum on even numbers from 12-45?

sum = 0; for (int i = 12; i