How to find LCM of two given Numbers in java

How to find LCM of two given Numbers in java .
SOURCE : LCM.java

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class LCM {

public static void main(String[] args) throws NumberFormatException,
IOException {
int lcm = 1;
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.println("enter the 1st number :");
int a = Integer.parseInt(br.readLine());

System.out.println("enter the 1st number :");
int b = Integer.parseInt(br.readLine());

for (int i = a; i <= a * b; i++) {

if (i % a == 0 && i % b == 0) {

lcm = i;
break;
}

}

System.out.println("LCM is : " + lcm);
}

}


INPUT

enter the 1st number :
5
enter the 1st number :
3





OUTPUT

LCM is : 15






Sandeep Kumar D

Hi, I have written and developed this post so that most of people will be benefited. I'm committed to provide easy and in-depth tutorials on various technologies.I hope it will help you a lot.

- Sandeep Kumar D

Follow Me @Google+




SHARE

    Blogger Comment
    Facebook Comment

0 comments :

Post a Comment