eclipse导入很容易,昨天上课学了一下用记事本写java,导入自定义类,这就麻烦了。
代码贴一下,方便操作:
package tom.jiafei; public class SquareEquation { double a,b,c; double root1,root2; boolean boo; public SquareEquation (double a,double b,double c) { this.a = a; this.b = b; this.c = c; if(a!=0) boo = true; else boo = false; } public void setCoefficient(double a,double b,double c) { this.a = a; this.b = b; this.c = c; if(a!=0) boo = true; else boo = false; } public void getRoots() { if(boo) { System.out.println("shi er yuan fang chen shi"); double disk = b*b - 4*a*c; if(disk>=0) { root1 = (-b+Math.sqrt(disk)/(2*a)); root2 = (-b-Math.sqrt(disk)/(2*a)); System.out.println("the roots are"+root1+" "+root2); } else System.out.println("mei you jie"); } else { System.out.println("bu shi er yuan fang chen shi gen"); } } }