Please note, this is a STATIC archive of website www.tutorialspoint.com from 11 May 2019, cach3.com does not collect or store any user information, there is no "phishing" involved.
Tutorialspoint

Compile and Execute Java Online

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);
         
         }
         
    
     }

Advertisements
Loading...

We use cookies to provide and improve our services. By using our site, you consent to our Cookies Policy.