Write a program in java to accept two numbers from user and find their H.C.F.
Answers
Answered by
3
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);
}
}
simarpreet73:
can you tell it without do while and while loop
Similar questions