大家好,我正在尝试遍历一个数组并用随机值填充每个数组元素。唯一的问题是我得到奇怪的输出,比如
[我@4b142196
但是在我的代码中使用它时它不起作用。这是我得到的:
package h05GrootsteWaarde;
import javax.swing.*;
import java.util.*;
public class GetallenGenerator extends JPanel {
public GetallenGenerator() {
}
int[] val = new int[21];
Random generator = new Random();
public void setRandomValue() {
for (int i = 0; i < val.length; i++) {
val[i] = generator.nextInt(201) - 100;
}
}
public int[] getRandomValue() {
return val;
}
}
这就是我调用函数的方式
package h05GrootsteWaarde;
import javax.swing.*;
import java.awt.event.*;
public class Bediening extends JPanel implements ActionListener {
GetallenGenerator generator;
private JButton bereken;
private JTextArea veld;
public Bediening(GetallenGenerator generator) {
this.generator = generator;
bereken = new JButton("Bereken kleinste");
bereken.addActionListener(this);
add(bereken);
veld = new JTextArea(13, 40);
veld.setEditable(false);
veld.setWrapStyleWord(true);
veld.setLineWrap(true);
add(veld);
generator.setRandomValue();
}
public void actionPerformed ( ActionEvent e ) {
String hoi = " " + generator.getRandomValue();
veld.append(hoi);
}
}