要求编程实现MyPoint类,使给定的Test类能正常运行,并实现指定的输出内容。 public class Test{ public static void main(String[] args) { MyPoint point; for (int i=0;i<5;i++ ){ point = new MyPoint(i*10.0,20.0); point.display(); } } }
时间: 2023-05-22 18:01:17 浏览: 112
用java实现Point类
5星 · 资源好评率100%
以下是 MyPoint 类的实现代码:
public class MyPoint {
private double x;
private double y;
public MyPoint(double x, double y) {
this.x = x;
this.y = y;
}
public void display() {
System.out.println("x=" + x + ", y=" + y);
}
}
输出结果为:
x=0.0, y=20.0
x=10.0, y=20.0
x=20.0, y=20.0
x=30.0, y=20.0
x=40.0, y=20.0
阅读全文