| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 556 人关注过本帖
标题:关于一道类的问题
取消只看楼主 加入收藏
枫xby
Rank: 5Rank: 5
等 级:职业侠客
威 望:8
帖 子:82
专家分:371
注 册:2014-10-19
结帖率:71.43%
收藏
已结贴  问题点数:5 回复次数:1 
关于一道类的问题
import java.util.Scanner;

public class TestQuadraticEuqation {
    public static void main(String[] args){
        //Scanner input = new Scanner(System.in);
        //System.out.print("please input a,b,c:");
        //double x = input.nextDouble();
        //double y = input.nextDouble();
        //double z = input.nextDouble();
         
         QuadraticEuqation quadraticEuqation = new QuadraticEuqation(0,0,0);
         quadraticEuqation.geta();
         quadraticEuqation.getb();
         quadraticEuqation.getc();
        
       if(quadraticEuqation.getDiscriminant()>0)
       System.out.println("The equation has two roots,root1 = : "+quadraticEuqation.getRoot1()+"root2 = "+quadraticEuqation.getRoot2());
        else if(quadraticEuqation.getDiscriminant()==0)
           System.out.println("The equation has the same root,root = "+quadraticEuqation.getRoot1());
        else
            System.out.println("The equaton has no roots");
    }

}
class QuadraticEuqation{
    Scanner input = new Scanner(System.in);
     private double a;
     private double b;
     private double c;
   
     QuadraticEuqation(double newa,double newb,double newc){
         a = newa;
         b = newb;
         c = newc;
        }
    public double geta(){
        System.out.print("please input a:");
        double a = input.nextDouble();
        return a;
    }
    public double getb(){
        System.out.print("please input b:");
        double b = input.nextDouble();
        return b;
        }
    public double getc(){
        System.out.print("please input c:");
        double c = input.nextDouble();
        return c;
        }
    public double getDiscriminant(){
        return b*b-4*a*c;
    }
    public double getRoot1(){
        return (-1*b+Math.pow(getDiscriminant(),1/2))/(2*a);
    }
    public double getRoot2(){
        return (-1*b-Math.pow(getDiscriminant(),1/2))/(2*a);
    }
   
}
错误是
please input a:1
please input b:2
please input c:1
The equation has the same root,root = Infinity
 请大神指教
搜索更多相关主题的帖子: please import double public 
2015-04-10 23:30
枫xby
Rank: 5Rank: 5
等 级:职业侠客
威 望:8
帖 子:82
专家分:371
注 册:2014-10-19
收藏
得分:0 
回复 2楼 hhwz
那个这个this的用法我不太懂 能大概解释一下吗
2015-04-11 19:13
快速回复:关于一道类的问题
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.021704 second(s), 10 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved