java Math.abs和Math.sqrtclass Line{double p1x;double p2x;double p1y;double p2y;public Line(double p1x,double p1y,double p2x,double p2y){this.p1x=p1x;this.p2x=p2x;this.p1y=p1y;this.p2y=p2y;}public String toString(){return "(" + p1x + "," + p1y + ")-(

来源:学生作业帮助网 编辑:作业帮 时间:2024/05/10 09:13:10

java Math.abs和Math.sqrtclass Line{double p1x;double p2x;double p1y;double p2y;public Line(double p1x,double p1y,double p2x,double p2y){this.p1x=p1x;this.p2x=p2x;this.p1y=p1y;this.p2y=p2y;}public String toString(){return "(" + p1x + "," + p1y + ")-(
java Math.abs和Math.sqrt
class Line
{
double p1x;
double p2x;
double p1y;
double p2y;
public Line(double p1x,double p1y,double p2x,double p2y){
this.p1x=p1x;
this.p2x=p2x;
this.p1y=p1y;
this.p2y=p2y;
}
public String toString(){
return "(" + p1x + "," + p1y + ")-(" + p2x + "," + p2y + ")";
}
public double getLength(){
double a=Math.abs(p1x-p2x);
double b=Math.abs(p1y-p2y);
double c=Math.sqrt(a*a+b*b);
\x09 return c;
}
\x09public static void main(String[] args)
\x09{
\x09Line line1 = new Line(10.5,20.1,100.0,50.0);
\x09Line line2 = new Line(-1.0,0.0,0.0,1.0);
\x09System.out.println(line1);
\x09System.out.println(line1.getLength());
\x09System.out.println(line2);
\x09System.out.println(line2.getLength());
\x09}
}
不能运行 总是找不到符号
怎么回事啊

java Math.abs和Math.sqrtclass Line{double p1x;double p2x;double p1y;double p2y;public Line(double p1x,double p1y,double p2x,double p2y){this.p1x=p1x;this.p2x=p2x;this.p1y=p1y;this.p2y=p2y;}public String toString(){return "(" + p1x + "," + p1y + ")-(
已运行(未作修改).运行结果:
(10.5,20.1)-(100.0,50.0)
94.36238657431254
(-1.0,0.0)-(0.0,1.0)
1.4142135623730951