在代碼中打印 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
提交
取消