import java.util.Scanner;
class A{
int a,b,r;
public A(int a,int b){
this.a=a;
this.b=b;
}
public int calculate() {
r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
}
class B{
int a,b;
public B(int a,int b){
this.a=a;
this.b=b;
}
A Max=new A(a,b);
public int calculate2 (){
return (a*b)/Max.calculate();
}
}
public class test5 {
public static void main(String[] args){
int a,b;
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
A test1=new A(a,b);
B test2=new B(a,b);
System.out.println("最大公约数为"+test1.calculate());
System.out.println("最小公因数为"+test2.calculate2());
}
}
为什么它会报java.lang.ArithmeticException异常?
class A{
int a,b,r;
public A(int a,int b){
this.a=a;
this.b=b;
}
public int calculate() {
r = a % b;
while (r != 0) {
a = b;
b = r;
r = a % b;
}
return b;
}
}
class B{
int a,b;
public B(int a,int b){
this.a=a;
this.b=b;
}
A Max=new A(a,b);
public int calculate2 (){
return (a*b)/Max.calculate();
}
}
public class test5 {
public static void main(String[] args){
int a,b;
Scanner sc=new Scanner(System.in);
a=sc.nextInt();
b=sc.nextInt();
A test1=new A(a,b);
B test2=new B(a,b);
System.out.println("最大公约数为"+test1.calculate());
System.out.println("最小公因数为"+test2.calculate2());
}
}
为什么它会报java.lang.ArithmeticException异常?