Computer Science, asked by yeshukiraah, 5 hours ago

Write a program to enter 2 numbers and print the LCM and
hcf of the numbers in array Java? (Simple program)​

Answers

Answered by madhumadhurya9
0

Answer:

import java.util.Scanner;

class LCM

{

  public static void main()

  {

     int temp1, temp2, num1, num2, temp, hcf, lcm;

     Scanner scanner = new Scanner(System.in);

     System.out.print("Enter First Number: ");

     num1 = scanner.nextInt();

     System.out.print("Enter Second Number: ");

     num2 = scanner.nextInt();

     scanner.close();

     temp1 = num1;

     temp2 = num2;

     while(temp2 != 0)

     {

        temp = temp2;

        temp2 = temp1%temp2;

        temp1 = temp;

     }

     hcf = temp1;

     lcm = (num1*num2)/hcf;

     System.out.println("HCF of input numbers: "+hcf);

     System.out.println("LCM of input numbers: "+lcm);

  }

}

Explanation:

Enter First Number: 25

Enter Second Number: 45

HCF of input numbers: 5

LCM of input numbers: 225

Similar questions