lcm with java

Solutions on MaxInterview for lcm with java by the best coders in the world

showing results for - "lcm with java"
Lilly
08 Sep 2019
1/*
2Easiest but slowest method
3*/
4class LCM 
5
6{ 
7
8    static void find_LCM(int num1, int num2) 
9
10    { 
11
12        System.out.println("Number 1: " + num1); 
13
14        System.out.println("Number 2: " + num2); 
15
16        long check_num = 1; 
17
18        while (true) 
19
20        { 
21
22            if ((check_num%num1) == 0 && (check_num%num2) == 0) 
23
24            { 
25
26                 long LCM = check_num; 
27
28                 System.out.println("The LCM is: " + LCM); 
29
30                 break; 
31
32            } 
33
34            else  
35
36                ++check_num; 
37
38        }  
39
40    } 
41
42}