Java program to find LCM of two number taken by user using while loop


Program
import java.util.*; public class LcMOfTwoNumber { public static void main(String[] args) { Scanner s=new Scanner(System.in); int a = s.nextInt(); int b = s.nextInt(); int lcm; lcm = (a > b) ? a : b; while(true) { if( lcm % a == 0 && lcm % b == 0 ) { System.out.format("The LCM of %d and %d is %d.", a, b, lcm); break; } ++lcm; } } }
Input
Output