Java Program To Find HCF LCM Of Two Numbers
Chapter:
Miscellaneous
Last Updated:
22-09-2018 08:48:48 UTC
Program:
/* ............... START ............... */
import java.util.Scanner;
public class JavaHCFLCM {
public static void main(String args[]) {
int a, b, x, y, t, hcf, lcm;
Scanner scan = new Scanner(System.in);
System.out.print("Enter Two Number : ");
x = scan.nextInt();
y = scan.nextInt();
a = x;
b = y;
while (b != 0) {
t = b;
b = a % b;
a = t;
}
hcf = a;
lcm = (x * y) / hcf;
System.out.print("HCF = " + hcf);
System.out.print("\nLCM = " + lcm);
}
}
/* ............... END ............... */
Output
Enter Two Number : 2 3
HCF = 1
LCM = 6
Tags
Find HCF LCM Of Two Numbers, Java, Miscellaneous, java program to find lcm of n numbers, lcm in java, lcm of two numbers in java example