-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMain25.java
More file actions
35 lines (23 loc) · 899 Bytes
/
Main25.java
File metadata and controls
35 lines (23 loc) · 899 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
package loopinjava;
import java.util.Scanner;
public class Main25 {
public static void main(String[] args) {
int dividend, divisor, remainder = 1, lcm, dividendClone, divisorClone;
Scanner input = new Scanner(System.in);
System.out.println("Find HCF (GCD) of two numbers.\n");
System.out.print("Enter first number: ");
dividend = input.nextInt();
System.out.print("Enter second number: ");
divisor = input.nextInt();
dividendClone = dividend;
divisorClone = divisor;
while (remainder != 0) {
remainder = dividend % divisor;
dividend = divisor;
divisor = remainder;
}
System.out.print("GCD: " + dividend + "\n");
lcm = (dividendClone * divisorClone) / dividend;
System.out.println("LCM: " + lcm + "\n");
}
}