我正在尝试制作一个程序,它接收一个数字,并将其添加到一个列表中,然后用按钮打印出列表,但每次运行程序时,输出都是错误的,例如,当我键入3时,它会输出“ids”=[333]有人能帮我吗,请。
ArrayList<Integer> list = new ArrayList<Integer>(); // store integers
result.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
int temp = Integer.parseInt(input.getText()); // get the input
list.add(temp); // add it to the list
JOptionPane.showMessageDialog(null, "The ID has been added");
} catch (NumberFormatException ex) {
JOptionPane.showMessageDialog(null, "The number you entered is not a valid Integer", "Invalid Input",
JOptionPane.WARNING_MESSAGE); // message to show if the input is invalid
}
}
});
show.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
for(int i=0;i<list.size();i++){ // print out the list
System.out.println("IDs : "+list.toString());
}
暂无答案!
目前还没有任何答案,快来回答吧!