-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcode.java
More file actions
34 lines (28 loc) · 876 Bytes
/
code.java
File metadata and controls
34 lines (28 loc) · 876 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
[2~[2~[2~[2~[2~import java.util.*;
public class code{
public static void main (String[] args) {
System.out.println("Please enter two numbers to find there LCM and HCF:");
Scanner sc = new Scanner(System.in);
int num1 = sc.nextInt();
int num2 = sc.nextInt();
sc.close();
int dividend, divisor, reminder, hcf, lcm;
if (num1 > num2) {
dividend = num1;
divisor = num2;
} else {
dividend = num2;
divisor = num1;
}
reminder = dividend % divisor;
while (reminder > 0) {
dividend = divisor;
divisor = reminder;
reminder = dividend % divisor;
}
hcf = divisor;
lcm = (num1 * num2)/hcf;
System.out.println("HCF : " + hcf);
System.out.println("LCM : " + lcm);
}
}