【发布时间】:2021-01-21 06:47:18
【问题描述】:
我有一个叫做“cambiar”的方法,我从一个叫做“articulos”的数组中接收数据,然后我把那个数据放在我的“datos”变量中。 但输出只是打印如下内容:
选择您要更改的文章 xx(我用这个xx字作为参考)
我的代码没有打印“datos”变量,我不知道为什么。
public ArrayList<Item> cambiar() {
String datos = "\n";
int cantidad;
String nombre;
for (int i = 0; i < articulos.size(); i++) {
cantidad = articulos.get(i).getCantidad();
nombre = articulos.get(i).getP().getNombre();
datos = "Articulo: " + nombre + ", Cantidad:" + cantidad + "\n";
}
int art = Integer.parseInt(JOptionPane.showInputDialog(null,"Select which article you would like to change\n"+ datos+"xx"));
articulos.get(art);
articulos.get(art).getCantidad();
int cuan = Integer.parseInt(JOptionPane.showInputDialog(null, "How many would you like buy?"));
articulos.get(art).setCantidad(cuan);
return articulos;
}
【问题讨论】:
-
没有minimal reproducible example,人们只能猜测您的问题是什么——正如您从问题的答案中所看到的那样。为什么不直接在方法
cambiar的for循环之前添加以下行:System.out.println(articulos.size());你知道,这叫做调试。
标签: java for-loop joptionpane