package javatute; import java.io.*; import java.util.Scanner; class LcmOfNnumber { public static void main(String args[]) throws Exception { Scanner in = new Scanner(System.in); int number1, number2, lcm = 1; System.out.println("enter number value of n "); int n = (in.nextInt()); while (n > 0) { number1 = lcm; lcm = 1; System.out.println("enter what number you want lcm"); number2 = in.nextInt(); for (int i = 2; i <= (number1 * number2); i++) { if ((number1 % i == 0) && (number2 % i == 0)) { lcm = lcm * i; number1 = number1 / i; number2 = number2 / i; i = i - 1; } } lcm = lcm * number1 * number2; n = n - 1; } System.out.println("LCM of given numbers : " + lcm); } }