public class A { /**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
B e=new B();
int h=e.f(12, 8);
System.out.println("最大公约数为:"+h);
C c=new C();
int k=c.f(12, 8);
System.out.println("最小公倍数为:"+k);
}
public class B {
public int f(int a,int b){
if(a%b==0)
return b;
return f(b,a%b);}}
public class C extends B{
public int f(int a,int b){
int m;
m=super.f( a, b);
return a*b/m;
}
}为什么运行结果是:最大公约数为:4
最小公倍数为:12,为什么最小公倍数不是24?怎样改啊?
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
B e=new B();
int h=e.f(12, 8);
System.out.println("最大公约数为:"+h);
C c=new C();
int k=c.f(12, 8);
System.out.println("最小公倍数为:"+k);
}
public class B {
public int f(int a,int b){
if(a%b==0)
return b;
return f(b,a%b);}}
public class C extends B{
public int f(int a,int b){
int m;
m=super.f( a, b);
return a*b/m;
}
}为什么运行结果是:最大公约数为:4
最小公倍数为:12,为什么最小公倍数不是24?怎样改啊?
比如把public int f(int a,int b)换成public int z(int a,int b)