我正在尝试输入一个2x2数组上的数据,我不能使用"for“,因为按钮的使用,第一位和第二位是可以的,但当我进入数组的下一维(我猜是j )时,有些东西是错误的。我希望能得到一些帮助,thx :)
public void actionPerformed (ActionEvent e){
if (e.getSource() == btingreso){
if (i<c1.length)
if (j<c1[i].length){
c1[i][j]= new compu_partes (txtnombre.getText(),Integer.parseInt(txtcantidad.getText()),txtcodigo.getText(),Double.parseDouble(txtprecio.getText()));
i++;
}
j++;
i=0;
}
}发布于 2013-09-16 04:46:26
注意你的缩进!它建议第二个if-block也包括j++;和i=0;,这两个语句是而不是。
另外,我认为您的索引增量略有错误。
这应该是可行的:
public void actionPerformed (ActionEvent e){
if (e.getSource() == btingreso){
if (i<c1.length){
if (j < c1[i].length){
c1[i][j] = new compu_partes(...);
j++;
}
if (j == c1[i].length){
i++;
j=0;
}
}
}
}https://stackoverflow.com/questions/18817277
复制相似问题