+ 1
Wap to print hcf and lcm of two numbers
3 Answers
+ 1
What is an issue?
0
here is the code :
public static void main(String[] args) {
System.out.println(gcd(12,18));
System.out.println(lcm(45,75));
}
static int gcd(int x , int y){
int gcd = 1;
int k = 2 ;
while( k <= x && k <= y){
if(x % k == 0 && y % k == 0){
gcd = k;
}
k++;
}
return gcd;
}
static int lcm(int x , int y){
int lcm = (x > y) ? x : y ;
while(true){
if(lcm % x == 0 && lcm % y == 0){
break;
}
lcm++;
}
return lcm;
}
0
I don't want gcd jst wanted hcf n lcm
n wanted to input two numbers other than scanner