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);
Comments
Leave a comment