-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathHCFLCM.java
More file actions
37 lines (37 loc) · 787 Bytes
/
HCFLCM.java
File metadata and controls
37 lines (37 loc) · 787 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import java.io.*;
class Hcf_Lcm
{
int n1,n2,hcf,lcm;
public static void main(String args[]) throws IOException
{
Hcf_Lcm call = new Hcf_Lcm();
call.readData();
call.display();
}
public void readData() throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
System.out.print("Enter 1st number : ");
n1 = Integer.parseInt(br.readLine());
System.out.print("Enter 2nd number : ");
n2 = Integer.parseInt(br.readLine());
}
public int findHCF(int a, int b)
{
if(a==0)
return b;
else
return findHCF(b%a,a);
}
public int findLCM(int a, int b, int hcf)
{
return (a*b)/hcf;
}
public void display()
{
hcf = findHCF(n1,n2);
lcm = findLCM(n1,n2,hcf);
System.out.println("\nHCF = " +hcf);
System.out.println("LCM = " +lcm);
}
}