写java程序时为什么会出现需要标示符和非法的类型开始
代码是classPoint{doublex,y,z;Point(double_X,double_Y,double_Z){x=_X;y=_Y;z=_Z;}voidsetX(...
代码是
class Point {
double x ,y ,z;
Point(double _X,double _Y,double _Z) {
x = _X;
y = _Y;
z = _Z;
}
void setX(double _X) {
x = _X;
}
double getdistance (Point p){
return (x-p._X)*(x-p._X)+(y-p._Y)*(y-p._Y)+(z-p._Z)*(z-p._Z);
}
}
public class Point {
public static void main (String[] args){
Point p = new Point (1.0,2.0,3.0);
Point p1 = new Point (0.0,0.0,0.0);
System.out.println(p.getdistance (p1));
p.setX(2.5);
System.out.println(p.getdistance(p1));
}
}
截图是 展开
class Point {
double x ,y ,z;
Point(double _X,double _Y,double _Z) {
x = _X;
y = _Y;
z = _Z;
}
void setX(double _X) {
x = _X;
}
double getdistance (Point p){
return (x-p._X)*(x-p._X)+(y-p._Y)*(y-p._Y)+(z-p._Z)*(z-p._Z);
}
}
public class Point {
public static void main (String[] args){
Point p = new Point (1.0,2.0,3.0);
Point p1 = new Point (0.0,0.0,0.0);
System.out.println(p.getdistance (p1));
p.setX(2.5);
System.out.println(p.getdistance(p1));
}
}
截图是 展开
2个回答
2014-01-26
展开全部
package com.test;
public class Point {
double x, y, z;
Point(double _X, double _Y, double _Z) {
x = _X;
y = _Y;
z = _Z;
}
void setX(double _X) {
x = _X;
}
double getdistance(Point p) {
// return (x - p._X) * (x - p._X) + (y - p._Y) * (y - p._Y) + (z - p._Z)
// * (z - p._Z);
// p的属性是x,y,z,不是_X,_Y,_Z
return (x - p.x) * (x - p.x) + (y - p.y) * (y - p.y) + (z - p.z)
* (z - p.z);
}
public static void main(String[] args) {
Point p = new Point(1.0, 2.0, 3.0);
Point p1 = new Point(0.0, 0.0, 0.0);
System.out.println(p.getdistance(p1));
p.setX(2.5);
System.out.println(p.getdistance(p1));
}
}
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询