我试图弄清楚为什么我的代码没有将硬币变化排列列表输出为 int 数组列表。它正在输出一些十六进制值(或任何I@64578ceb
值)。
有什么想法吗?
称呼:
System.out.println("Permutations List: " + dan.makeChange(27));
代码:
public class Person {
int[] denominations, coinValues;
List<int[]> resultsList;
public Person() {
denominations = new int[]{25, 10, 5, 1};
resultsList = new ArrayList<int[]>();
}
public List<int[]> makeChange(int change) {
return resultsList= changeMaker(change, new int[] {0,0,0,0});
}
public List<int[]> changeMaker(int change, int[] toAdd) {
if (change == 0) {
resultsList.add(toAdd);
return resultsList;
}
for (int i = 0; i < denominations.length; i++) {
if (change >= denominations[i]) {
int[] temp = toAdd;
temp[i]++;
resultsList = changeMaker(change-denominations[i], temp);
}
}
return resultsList;
}
输出:
Permutations List: [[I@64578ceb, [I@64578ceb, [I@64578ceb, [I@64578ceb, [I@64578ceb, [I@64578ceb, etc...