import java.io.*;
class Max
{
BufferedReader br=new
BufferedReader(new InputStreamReader(System.in));
int a,b,big,small,temp;
public void show()throws
Exception
{
System.out.println("Enter
the 1st number:");
a=Integer.parseInt(br.readLine());
System.out.println("Enter
the 2nd number:");
b=Integer.parseInt(br.readLine());
if(a>b)
{
big=a;
small=b;
}
else
{
big=b;
small=a;
}
for(int i=1;i<=big;i++)
{
if(((big*i)%small)==0)
{
int lcm=big*i;
System.out.println("The LCM
is = "+(lcm));
break;
}
}
temp=1;
while(temp!=0)
{
temp=big%small;
if(temp==0)
{
System.out.println("GCD is
"+small);
}
else
{
big=small;
small=temp;
}
}
}
public static void main(String
args[])throws Exception
{
Max ob=new Max();
ob.show();
}
}
Sample output:
Enter the 1st number:
23
Enter the 2nd number:
12
The LCM is = 276
GCD is 1
Enter the 1st number:
24
Enter the 2nd number:
12
The LCM is = 24
GCD is 12
You literally just saved my project from drowning. Grateful!!!
ReplyDelete-Kopai from Kolkata