在这个类中,我定义了一个构造函数,它初始化一个数组并用Point2D.Double填充它.我想定义一个toString方法,输出数组中的Point2D.Double.所以在toString方法中,我创建一个for循环,返回数组中的每个Point2D.Double.问题是,我不知道为什么Eclipse告诉我for语句中的更新是死代码.
import java.awt.geom.Point2D;
public class SimplePolygon {
public int n; // number of vertices of the polygon
public Point2D.Double[] vertices; // vertices[0..n-1] around the polygon
// boundary
public SimplePolygon(int size) {
n = size;
vertices = new Point2D.Double[n]; // creates array with n size. Elements are doubles.
for(int i = 0; i < n; i++)
{
Point2D.Double point = new Point2D.Double(Math.random() * 6, Math.random() * 6);
vertices[i] = point;
}
}
public String toString() {
for(int i = 0 ; …Run Code Online (Sandbox Code Playgroud)