您好,我是编程新手,很想获得帮助。我试图在Eclipse中编写一个简单的程序,以计算出一些基本方程式。我已经做了2个包裹, “方程式”和“工作区”。
这是方程式程序包中的“ quadraticEquation”类。
package Equations;
import java.util.*;
public class quadraticEquation {
//ax^2 + bx + c = 0
double a,b,c;
Scanner input= new Scanner(System.in);
void calculateQuadEq() {
System.out.println("Enter a");
a = input.nextDouble();
System.out.println("Enter b");
b = input.nextDouble();
System.out.println("Enter c");
c = input.nextDouble();
double z = Math.pow(b, 2) - (4*a*c);
if(z<0) {
System.out.println("This equation has no real roots");
} else if(z==0) {
double m = -b/(2*a);
System.out.println("There are 2 equal roots to this equation, " + m + " and " + m);
} else if(z>0) {
double m = (-b + (Math.pow(b, 2) - 4*a*c))/2*a;
double n = (-b - (Math.pow(b, 2) - 4 *a*c))/2*a;
System.out.println("There are 2 real roots to this equation, " + m + " and " + n);
}
}
}
我可以在同一软件包中成功运行变量calculateQuadEq
(已尝试过),但是在其他软件包中却无法运行。我很累像这样导入类文件。
我该怎么做?