Computer Science, asked by parthomsarwade, 1 year ago

write a program to accept 2 numbers and find their lcm and hcf
use scanner class
write in blue j
use for loop​

Answers

Answered by aniket2002kumarak
3

Answer:

Explanation:To find the HCF and LCF of two number in Java Programming, you have to ask to the user to enter the two number, to find the HCF and LCF of the given two number to display the value of the HCF and LCM of the two numbers on the output screen as shown in the following program.

Java Programming Code to Find HCF LCM of Two Numbers

Following Java Program ask to the user to enter any two number to find HCF & LCM, then display the result on the screen :

/* Java Program Example - Find HCF LCM of Two Numbers */

import java.util.Scanner;

public class JavaProgram

{

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);

}

}


parthomsarwade: u have to use for loop
prithvi1243: hi
parthomsarwade: also can u explain why u took each variable
prithvi1243: time pass
prithvi1243: you don't know anything
parthomsarwade: i don't know thats y i am asking
parthomsarwade: but thanks
prithvi1243: follow me
Similar questions