import java.io.*;
class TEN{
public static int determineLCM(int a, int b) {
int num1, num2;
if (a > b) {
num1 = a;
num2 = b;
} else {
num1 = b;
num2 = a;
}
for (int i = 1; i <= num2; i++) {
if ((num1 * i) % num2 == 0) {
return i * num1;
}
}
return 0;
}
public static int determineHCF(int a, int b) {
if (b==0)
return a;
else
return determineHCF(b, a % b);
}
public static void main(String[] args)throws Exception {
TEN cal = new TEN();
BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter first number: ");
String input1 = reader.readLine();
int num1=Integer.parseInt(input1);
System.out.println("Enter second number: ");
String input2 = reader.readLine();
int num2=Integer.parseInt(input2);
int lcm = cal.determineLCM(num1, num2);
System.out.println("LCM of two numbers= "+lcm);
int hcf = cal.determineHCF(num1, num2);
System.out.println("HCF of two numbers= "+hcf);
}
}
|