java - 将数组中的值相除
问题描述
当总数达到一定限制时,我试图将数组中的值分开。
所以这些是我目前拥有的数组。
ArrayList<String> IDname = new ArrayList<>(); // this contains the name of the ID (Max. 10 names)
ArrayList<Integer> qty = new ArrayList<>(); // this contains the values acquired from user input (Max. 10 values)
我想要做的是,一旦我获得了每个盒子的最大油漆输入,我应该确保数组中的每个 ID 及其数量都在每个盒子中。
例如:IDnames 有 ID1,ID2,ID3,ID4
权重有 343,274,199,197
每个盒子的最大值 = 12
我想确保每个盒子至少有每个 ID 的数量,然后显示在一个文本字段上,告诉每个盒子中的数量和 ID 名称
例如:
框 1 = ID1、数量、ID2、数量、ID3、数量 ...
框 2=....
这如何在代码中完成?
解决方案
如果我理解,你可以做这样的事情:
public void addPaint ( String id, Integer weight) {
IDname.add(id);
qty.add(weight);
}
这会将值添加到两个数组中,并且它们将具有相同的索引。如果你想显示值:
for(int i=0; i<12; i++){
System.out.println(IDname[i]);
System.out.println(weight[i]);
}