Showing posts with label lcm-of-two-numbers. Show all posts
Showing posts with label lcm-of-two-numbers. Show all posts

Sunday, July 5, 2020

Write a program to input two integers and find the LCM of two numbers?(10,12..LCM=60 )

39)  Write a program to input two integers and find the LCM of two numbers?(10,12..LCM=60 )

import java.util.*;
public class LCM
{
   public static void main(String args[ ])
   {
      Scanner sc = new Scanner (System.in);
      System.out.println("Enter two numbers");
      int a = sc.nextInt();
      int b = sc.nextInt();
      for(int i = Math.max(a,b);i<a*b;i++)
      {
              if(i%a==0&&i%b==0)
              {
                  System.out.println("L.C.M of "+a+" and "+b+" = "+i);
                  break;
              }
      }
   }
}

output : 


 jhvghvgk ;nkjn ,nkjhj