在代码中打印 f(i).x 时,将显示正确的 x 值。但是当我试图得到作为例子:points.get(2).x或任何其他值,我总是得到相同的x值。任何帮助都会很棒。主要类:import java.util.ArrayList;public class Main { public static ArrayList<Point> points = new ArrayList(); public static void main(String[] args) { for (float i = -5; i <= 5; i+=0.1) { points.add(f(i)); } for (int i = 0; i < points.size(); i++) { System.out.println(points.get(i).x); // shows always the same number: 4.95... } } public static Point f(float x) { return new Point(x, (-0.15f*((x + -2.1f) * (x + -2.1f)) + 4.3f)); }}积分等级:public class Point { public static float x; public static float y; public Point(float x_, float y_) { x = x_; y = y_; }}
1 回答

慕桂英4014372
TA贡献1871条经验 获得超13个赞
添加回答
举报
0/150
提交
取消