Answer to Question #13972 in Java | JSP | JSF for aynalem

Question #13972
4.Write a program that accepts two numbers from the user and return the LCM of two numbers
1
Expert's answer
2012-09-04T10:35:53-0400
import java.util.Scanner;

public class Test {

public static void
main(String[] args) {
double a = 0;
double b = 0;
Scanner s = new
Scanner(System.in);
System.out.println("Input numbers: ");
a =
s.nextDouble();
b = s.nextDouble();
double x = a;
double y =
b;
while (a != b) {
if (a > b)
a = a - b;
else
b = b -
a;
}
System.out.println("LCM= " + x * y / a);

}

}

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
APPROVED BY CLIENTS