Java program to calculate HCF and LCM


Program 

package com.candidjava;

public class FindHCFAndLCM
{

	public static void main(String args[])
	{
		int a, b, x, y, t, hcf, lcm;

		x = 6;
		y = 10;

		a = x;
		b = y;

		while (b != 0)
		{
			t = b;
			b = a % b;
			a = t;
		}

		hcf = a;
		lcm = (x * y) / hcf;

		System.out.print("HCF and LCM of : " + x + " and " + y + " is :\n");
		System.out.print("HCF = " + hcf);
		System.out.print("\nLCM = " + lcm);
	}
}

Output

HCF and LCM of : 6 and 10 is :

HCF = 2

LCM = 30



Related Post

Comments

Hi
         Hi

©candidjava.com