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");
        }
        
    }
    
    
    
    
    
    
    
    
}
View Code

相关文章:

  • 2021-11-27
  • 2021-10-22
  • 2021-11-30
  • 2022-12-23
  • 2021-11-02
  • 2022-01-11
猜你喜欢
  • 2022-12-23
  • 2021-11-04
  • 2022-12-23
  • 2021-07-10
  • 2021-07-28
  • 2022-01-12
相关资源
相似解决方案