+ 1

Wap to print hcf and lcm of two numbers

15th Mar 2017, 2:33 PM
Manoj Agrawal
Manoj Agrawal - avatar
3 Answers
+ 1
What is an issue?
15th Mar 2017, 2:59 PM
MichaƂ Bujakowski
MichaƂ Bujakowski - avatar
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; }
15th Mar 2017, 2:38 PM
ahmed khattab
ahmed khattab - avatar
0
I don't want gcd jst wanted hcf n lcm n wanted to input two numbers other than scanner
15th Mar 2017, 3:03 PM
Manoj Agrawal
Manoj Agrawal - avatar