【发布时间】:2014-06-07 12:02:45
【问题描述】:
我无法将从一个类传递的变量存储到另一个类的数组中。
我将一个已在 A 类中扫描的双精度传递给 B 类,我希望将双精度存储在双精度数组中,只要类 A 中的扫描仪@hasNext() .
我在B 类中的代码类似于这样:
// I can't seem to get the passed doubles to be stored as individual elements of the array
public class B {
public final static int MAX_SIZE = 200;
public int i;
public double passedOne;
public void store() {
double[] storedOneVars = storedOneVars[MAX_SIZE]; // create a system to store variables in the array
for (i = 0; i < MAX_SIZE; i++) {
storedOneVars[i] = passedOne;
}
for (double s : storedOneVars) {
System.out.println(s);
}
}
public static void main(String[] args) {
// TODO Auto-generated method stub
new NumberRow().store();
}
}
我愿意接受建议:D
【问题讨论】:
-
代码的意义何在?
-
@ErikAllik 我认为 OP 正在学习如何传递变量。我认为这就是重点
-
变量不通过;值是。
-
对不起
pass by reference,但你知道我的意思:) -
对不起,我缺乏编程术语,对此仍然很陌生,重点是在我的 B 类中构建一种“数据库”(双数组),以便我以后可以检索它,从下一节课。