public class GroceryCosts{ public static void main(String []args){ int[][] prices = { {3, 5, 3}, {8, 9, 7}, {1, 8, 8}, }; int total = 0; for (int i=0;i<=2;i++) { int totalFoodLion = 0; int totalHarrisTeeter = 0; int totalWalMart = 0; for(int j=0;j<=2;j++) { System.out.print("$" + prices[i][j] + " "); totalFoodLion = totalFoodLion + prices[i][j]; totalHarrisTeeter = totalHarrisTeeter + prices[i][j]; totalWalMart = totalWalMart + prices[i][j]; total = total + prices[i][j]; } if(i==0) System.out.println("Total cost for Food Lion is $" + totalFoodLion); if(i==1) System.out.println("Total cost for Harris Teeter is $" + totalHarrisTeeter); if(i==2) System.out.println("Total cost for WalMart is $" + totalWalMart); } System.out.println("Total cost for all stores is $" + total); } }
We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy. Accept Learn more