Computer Science, asked by ArnabThor, 1 year ago

. Problems on Constructor:
1. Write a class program in Java with the following specifications:
Class name : Hcflcm
Data members/instance variables : int ab
Member functions:
hcflcm (int x, int y): constructor to initialize a=x and b=y.
void calculate(): to find and print hcf and lcm of both the numbers​

Answers

Answered by utkarshmishra9819
15

And your Stress relieved ☺

Follow me if want your problems solved quickly and above all completely correctly.☺

Attachments:
Answered by masterav
0

Answer:

import java.util.*;

public class sum7

{

int a,b;

public Hcflcm(int x, int y)

   {

       a=x;

       b=y;

   }

   void calculate()

   {

       int hcf,lcm,i;

       for(i=a;i<=a;i++)

       {

           if(a%i==0&&b%1==0)

           {

               hcf=i;

           }

   }

   lcm=a*b/hcf;

   System.out.println("LCM = "+lcm);

   System.out.println("HCF = "+hcf);

}

public static void main()

   {

       Scanner sc=new Scanner(System.in);

       int x1,y1;

       System.out.println("Enter numbers");

       x1=sc.nextInt();

       y1=sc.nextInt();

       Hcflcm ob=new Hcflcm(x1,y1);

       ob.calculate();

   }

}

Explanation:

dpsnt student??

Similar questions