I have an array of customer names:
String[] customers = {"Joe Dirt", "John Dirt", "Josh Dirt"};
I also have a two-dimensional array that has acct numbers/payments:
double[][] payments = {{1011,12,54,39},{1012,55,65,48},{1013,56,92,55}};
I need to match and print out the customer's name with their account and payments. The arrays are already sorted in order I just need to print out "Joe Dirt 1011, 12, 54, 55" and so on.. I'm trying to understand how to loop through the two-dimensional array.
This is what I have:
public static ArrayList<String> combineArray(String[] customers,
double[][] payments) {
ArrayList<String> customerPayments = new ArrayList<String>();
String result = "";
String custName = "";
String acctInfo = "";
for (String n : customers) {
custName = n;
for (double[] x : payments) {
for (double y : x) {
acctInfo = String.valueOf(y);
}
}
result = custName + acctInfo;
customerPayments.add(result);
}
return customerPayments;
}
It's printing out the customer names correctly, but printing out only the last value of the payment two-dimensional array. ex.
Joe Dirt55
John Dirt55
Josh Dirt55
What am I overlooking here?