0% found this document useful (0 votes)
9 views5 pages

Code& Homework

The document contains two Java programs for calculating the Highest Common Factor (HCF) and Lowest Common Multiple (LCM) of two numbers. The first program uses a constructor to initialize the numbers and calculates both HCF and LCM, while the second program focuses solely on calculating the LCM using a loop. Both programs take user input for the numbers and display the results.

Uploaded by

nakulmandal1958
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
9 views5 pages

Code& Homework

The document contains two Java programs for calculating the Highest Common Factor (HCF) and Lowest Common Multiple (LCM) of two numbers. The first program uses a constructor to initialize the numbers and calculates both HCF and LCM, while the second program focuses solely on calculating the LCM using a loop. Both programs take user input for the numbers and display the results.

Uploaded by

nakulmandal1958
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

/*A Java program to find the HCF and LCM of

two Numbers using Constructor*/


import java.util.Scanner;

import java.lang.*;

class HcfLcm

int n1,n2,t1,t2,t;

HcfLcm(int x,int y)

n1=x;

n2=y;

void Calculate()

t1=n1;

t2=n2;

while(t2!=0)

t=t2;

t2=t1%t2;

t1=t;
}

int hcf=t1;

int lcm = (n1*n2)/hcf;

System.out.println("H.C.F= "+hcf);

System.out.println("L.C.M= "+lcm);

void main()

int x,y;

Scanner sc= new Scanner(System.in);

System.out.print("Enter any two Number:");

x=sc.nextInt();

y=sc.nextInt();

HcfLcm hl = new HcfLcm(x,y);

hl.Calculate();

}
/*A Java program to find the LCM of two Numbers*/
import java.util.Scanner;

class LCM

void main()

int a,b,lcm;

Scanner sc= new Scanner(System.in);

System.out.println("Enter two number:");

a=sc.nextInt();

b=sc.nextInt();

lcm=(a>b)?a:b;

while(true)

if(lcm%a==0 && lcm%b==0)

break;

lcm++;

System.out.println("Lcm of "+a+" and "+b+" ="+lcm);

You might also like