java编译找不到符号
publicclassPoint2D{intx;inty;publicPoint2D(){x=0;y=0;}publicPoint2D(intx,inty){//构造方法...
public class Point2D {
int x;
int y;
public Point2D(){
x=0;
y=0;
}
public Point2D(int x,int y){ //构造方法
this.x=x;
this.y=y;
}
void offset(int a,int b){
x=x+a;
y=y+b;
}
void distance(Point2D a,Point2D b){//打印两点之间的距离
float m;
m=(float)java.lang.Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
System.out.print("二维空间两点之间的距离:");
System.out.println("m="+m);
}
}
public class Point3D extends Point2D{
int x,y,z;
Point3D(int x,int y,int z){
this.x=x;
this.y=y;
this.z=z;
}
Point3D(){
super();
z=0;
}
Point3D(Point2D p,int z){
//构造并初始化一个与指定的 Point2D对象具有相同位置的点
x=p.x;
y=p.y;
this.z=z;
}
void offset(int a,int b,int c){
x=x+a;
y=y+b;
z=z+c;
}
void distance(Point3D a,Point3D b){//两点的空间距离
float n;
n=(float)java.lang.Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
System.out.print("三维空间两点之间的距离:");
System.out.println("n="+n);
}
public static void main(String[] args){
/*Point 2D p2d1,p2d2;
* Point 3D p3d1,p3d2;
* p2d1=new Point2D(1,2);//为对象声明空间
p2d2=new Point2D(2,3); //这里将声明和创建对象写在一起,也可以分开写
p3d1=new Point3D(1,2,3);
p3d2=new Point3D(2,3,4);
*/
Point2D p2d1=new Point2D(1,2);//为对象声明空间
Point2D p2d2=new Point2D(2,3); //这里将声明和创建对象写在一起,也可以分开写
Point3D p3d1=new Point3D(1,2,3);
Point3D p3d2=new Point3D(2,3,4);
p2d1.distance(p2d1, p2d2);
p3d1.distance(p3d1, p3d2);
}
}
哪里错了 符号:类 Point2D找不到 展开
int x;
int y;
public Point2D(){
x=0;
y=0;
}
public Point2D(int x,int y){ //构造方法
this.x=x;
this.y=y;
}
void offset(int a,int b){
x=x+a;
y=y+b;
}
void distance(Point2D a,Point2D b){//打印两点之间的距离
float m;
m=(float)java.lang.Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
System.out.print("二维空间两点之间的距离:");
System.out.println("m="+m);
}
}
public class Point3D extends Point2D{
int x,y,z;
Point3D(int x,int y,int z){
this.x=x;
this.y=y;
this.z=z;
}
Point3D(){
super();
z=0;
}
Point3D(Point2D p,int z){
//构造并初始化一个与指定的 Point2D对象具有相同位置的点
x=p.x;
y=p.y;
this.z=z;
}
void offset(int a,int b,int c){
x=x+a;
y=y+b;
z=z+c;
}
void distance(Point3D a,Point3D b){//两点的空间距离
float n;
n=(float)java.lang.Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y)+(a.z-b.z)*(a.z-b.z));
System.out.print("三维空间两点之间的距离:");
System.out.println("n="+n);
}
public static void main(String[] args){
/*Point 2D p2d1,p2d2;
* Point 3D p3d1,p3d2;
* p2d1=new Point2D(1,2);//为对象声明空间
p2d2=new Point2D(2,3); //这里将声明和创建对象写在一起,也可以分开写
p3d1=new Point3D(1,2,3);
p3d2=new Point3D(2,3,4);
*/
Point2D p2d1=new Point2D(1,2);//为对象声明空间
Point2D p2d2=new Point2D(2,3); //这里将声明和创建对象写在一起,也可以分开写
Point3D p3d1=new Point3D(1,2,3);
Point3D p3d2=new Point3D(2,3,4);
p2d1.distance(p2d1, p2d2);
p3d1.distance(p3d1, p3d2);
}
}
哪里错了 符号:类 Point2D找不到 展开
1个回答
展开全部
我用你的代码运行了,没错啊
结果如下:
二维空间两点之间的距离:m=1.4142135
三维空间两点之间的距离:n=1.7320508
结果如下:
二维空间两点之间的距离:m=1.4142135
三维空间两点之间的距离:n=1.7320508
更多追问追答
追问
可是我编译提示找不到符号,你是怎么运行的呢
追答
package com.test;
public class Point2D {
int x;
int y;
public Point2D(){
x=0;
y=0;
}
public Point2D(int x,int y){ //构造方法
this.x=x;
this.y=y;
}
void offset(int a,int b){
x=x+a;
y=y+b;
}
void distance(Point2D a,Point2D b){//打印两点之间的距离
float m;
m=(float)java.lang.Math.sqrt((a.x-b.x)*(a.x-b.x)+(a.y-b.y)*(a.y-b.y));
System.out.print("二维空间两点之间的距离:");
System.out.println("m="+m);
}
}
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询
广告 您可能关注的内容 |