I'm a beginner with code, so I apologize if my data structure and logic is poor practice. I need to print out the total sale for each product. For example, for "mac" it would be labeled as Category 0, and "iphone" would be labeled as Category 1.
I am having trouble matching the index position for the categories with the sum of each respective category. I really just need some kind of for loop. I realize I can make a 2D array as well as use intstream, but I haven't learned it yet. This is only a portion of the code, so using a 2D array would really complicate things.
Right now, I am trying the following:
public static int[] totalSale( int[] mac, int[] iphone, int[] ipad, int[] ipod ){
int[] totalSale = {0,0,0,0};
int sum = 0;
for (int i : mac) {
sum += i;
}
for (int i = 0; i < totalSale.length; i++) {
System.out.println("Total sale for category " + i + ": $" + sum);
}
return totalSale;
}