Java Online Compiler
Example: Java Program to Find LCM of Two Numbers using While loop
C
C++
C#
Java
Python
PHP
Main.java
STDIN
Run
// Java Program to Find LCM of Two Numbers using While loop import java.util.Scanner; public class Main { public static void main(String[] args) { Scanner in = new Scanner(System.in); int p, q, x; // p & q - To store the two positive numbers // x - To store the LCM number System.out.println ("-----Enter the two positive integer numbers-----"); p = in.nextInt(); q = in.nextInt(); x = p > q ? p : q; while (true) { if (x % p == 0 && x % q == 0) { System.out.println ("\nThe LCM of the " + p + " and " + q + " numbers is " + x); break; } ++x; } } }
120 140
Output
Clear
ADVERTISEMENTS