class Solution{ private int a; private int b; private int sum=0; public Solution(int i,int j) { this.a=i; this.b=j; this.sum=this.a*this.b; } //最大公因数 public int HCF() { while(this.a%this.b!=0) { int temp=this.b; //简单的转化导致它们的结果进行了交换 this.b=this.a%this.b; //从此求某两个数的最大公因数只要传数进去即可 this.a=temp; //功能强大代码简单 } return b; } //最小公倍数 public int LCM() { return sum/HCF(); } } public class Main { public static void main(String[] args) { Solution space=new Solution(12,6); System.out.println(space.HCF()); System.out.println(space.LCM()); } }