01 August 2018

Java Program to find LCM of two(2) numbers.

//Program to find LCM of  two(2) numbers.
import java.util.Scanner;
class lcm
      {
  public static void main(String args[])
{
int a,b,max,lcm=1;
Scanner obj=new Scanner(System.in);
System.out.print("enter 1st number-");
a=obj.nextInt();
System.out.print("enter 2nd no.-");
b=obj.nextInt();
max=(a>b)?a:b;
if(max%a==0 && max%b==0)
  lcm=max;
else
   lcm=a*b;

System.out.println("lcm of "+a+" and "+b+" is\t"+lcm);
}
      }

No comments:

Post a Comment

To convert from Upper case to lowercase(A to a)

//converting from Upper to lower(A to a) import java.util.*; class case { public static void main(String args[]) { System.out.pr...