本来返回值没有问题,但到下一行m就变成了0
源码
package projcet_zuoye;
import java.util.Scanner;
class A1{
public int gcd(int a,int b) {
return b==0?a:gcd(b,a%b);
}
public int f(int a,int b) {
if(a>b)
return gcd(a,b);
else
return gcd(b,a);
}
}
class B1 extends A1{
public int f(int a,int b) {
int m = super.f(a,b);
if(0 == m)
return a*b;
else
return (a*b)/m;
}
}
public class Example_9 {
public static void main(String[] args) {
Scanner reader = new Scanner(System.in);
int a,b;
System.out.println("请输入运算的数a,b");
a = reader.nextInt();
b = reader.nextInt();
A1 a1 = new A1();
B1 b1 = new B1();
System.out.println(a+","+b+"的最大公约数是:"+a1.f(a, b));
System.out.println(a+","+b+"的最小公倍数是:"+b1.f(a, b));
}
}