Back To Java Loops Index
//program to find lcm and hcf of 2 numbers using while loop public class whilelcmhcf { public static void main(String[] args) { int a,b,c; a=10; b=5; c=a*b; while(a!=b) { if(a>b) a=a-b; else b=b-a; } System.out.println("HCF = " + a); System.out.println("LCM = " + c/a); } }