Question

Please write answer in java with no input functions: Our goal is to write a function...

Please write answer in java with no input functions:

Our goal is to write a function (not a snippet—no more snippets from this point forward) called lcm that computes the least common multiple of two integers. While there are clever algorithms for solving this problem, we encourage you to try something simple.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

class Main {

public static int gcd(int a, int b)

{

if (a == b)

return a;

if (a > b)

return gcd(a-b, b);

return gcd(a, b-a);

}

public static int leastCommonDenominator(int a, int b){

return (a*b)/gcd(a, b);

}

public static void main(String[] args) {

System.out.println("Lcm of 2 and 4 is: " +leastCommonDenominator(2,4));

}

}

================================================
SEE OUTPUT

Thanks, PLEASE COMMENT if there is any concern.

Add a comment
Know the answer?
Add Answer to:
Please write answer in java with no input functions: Our goal is to write a function...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT