HCF and LCM
class HcfNum{ private int Int; private int Int2; HcfNum(int x, int y){ Int = x; Int2 = y; } private int HcfIs(){ int temp,temp2; temp = Math.max(Int,Int2); temp2 = Math.min(Int, Int2); while(temp!=0 && temp2!=0){ int rem = temp%temp2; if(rem == 0) { break; } int chng = temp2; temp2 = temp%temp2; temp = chng; } return temp2; } public void example(){ System.out.println("HCF is " + HcfIs()); } }
LCM
LCM can be calculated using a*b/HCF