编写类 Point, 用以表示直角坐标系中的点。其中 distance 方法返回当前点到坐标原点的距离
public class Point{
private double x,y;
Point(double a ,double b){
1
}
double distance( ) {
2 Math.sqrt(x*x+y*y);
}
public static void main(String args[]){
Point p1=new Point(3,4);// 创建坐标为的点 p1(3,4)
System.out.print(3); // 输出 p1 到原点的距离
}
}