java - Outputting List<int[]> does not work -
this question has answer here:
- what's simplest way print java array? 23 answers
i'm trying figure out why code isn't outputting coin change permutations list list of int arrays. it's outputting hex value (or whatever i@64578ceb
is).
any thoughts?
call:
system.out.println("permutations list: " + dan.makechange(27));
code:
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; } (int = 0; < denominations.length; i++) { if (change >= denominations[i]) { int[] temp = toadd; temp[i]++; resultslist = changemaker(change-denominations[i], temp); } } return resultslist; }
output:
permutations list: [[i@64578ceb, [i@64578ceb, [i@64578ceb, [i@64578ceb, [i@64578ceb, [i@64578ceb, etc...
int[]
doesn't have pretty tostring()
display numbers, need write own method accept int[]
, print in whatever format want
Comments
Post a Comment