一个程序编写题

chenhui2078289 2009-02-17 08:45:46
问题是这样的:编写一个程序,求解一元二次方程:a*x*x+b*x+c=0.参数a、b及c从命令行输入。
然后我写的程序是

public class a001{

public static void main(String []args){

if(args.length!=3)
{
System.out.println("Usage: java SolveQuadratic aCoef bCoef cCoef \nExample java a001 1 2 1");
System.exit(-1);
}
double a,b,c;
double a=double.parseDouble(args[0]);
if(Math.abs(a)<Math.pow(10,-6))
System.out.println("a=0,This is not a quadratic");
System.exit(-1);
double b=double.parsedouble(args[1]);
double c=double.parsedouble(args[2]);
double d=b*b-4*a*c;
System.out.println("This is a quadratic");
if(Math.abs(d)<Math.parseDouble(10,-6))
System.out.println("this quadratic have two equal roots"+(-b)/(2*a));

if(d>0){

System.out.println("The first answer "+(-b-Math.sqrt(d))/2*a);
System.out.println("The second answer "+(-b+Math.sqrt(d))/2*a);
}
else
{ double e=(-b)/2*a;
double f=Math.sqrt((-d)/2*a);
System.out.println("The first answer "+e+"+"+f+"i");
System.out.println("The second answer "+e+"-"+f+"i");
}
}
}






然后提示说:double a=double.parseDouble(args[0]);double b=double.parsedouble(args[1]);double c=double.parsedouble(args[2]);这三句需要class,不知怎么解决。
谢谢您的关注。
...全文
98 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
cantalou 2009-02-19
  • 打赏
  • 举报
回复
up
chenhui2078289 2009-02-17
  • 打赏
  • 举报
回复
谢拉,现在刚刚发现您说的这个问题,还有就是a,b,c,刚已经定义过了,不用再定义了。
chenhui2078289 2009-02-17
  • 打赏
  • 举报
回复
谢拉,现在刚刚发现您说的这个问题,还有就是a,b,c,刚已经定义过了,不用再定义了。
酒剑仙 2009-02-17
  • 打赏
  • 举报
回复
double.parseDouble(args[0]);

感觉不对啊

Double.parseDouble(args[0]);

这是封装对象才有的数据转换方法吧
MT502 2009-02-17
  • 打赏
  • 举报
回复
double a=double.parseDouble(args[0]);
应该是
double a=Double.parseDouble(args[0]);

62,635

社区成员

发帖
与我相关
我的任务
社区描述
Java 2 Standard Edition
社区管理员
  • Java SE
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧