public static void main(String[] args)
{
int [] [] totals = { {500, 150, 575, 500},
{200, 700, 175, 200},
{300, 75, 100, 400},
{100, 185, 118, 250},
{600, 260, 663, 345} };
// header
System.out.printf("\t\t%20s\n\n", "Overall Sales Distribution:");
System.out.print(" ");
// column headers for table
for (int sp = 0; sp < totals[0].length; sp++)
{
System.out.printf("SalesP%d ", sp + 1);
}
System.out.print("Total"); // total sales columns
// row headers for table
for(int prod = 0; prod < totals.length; prod++)
{
// print row totals in column total
[I] for(int row = 0; row < totals.length; row++)
{
int sum = 0;
for(int column = 0; column < totals[row].length; column++)
{
sum += totals [row][column];
System.out.printf("%8d", sum);
}[/I]
}
System.out.printf("\nProd%d", prod + 1);
// print array values in table
for(int sp : totals[prod])
{
System.out.printf("%10d", sp);
}
}
System.out.print("\nTotal");
for(int r = 0; r < totals.length; r++)
{
int total = 0;
for(int c = 0; c < totals[r].length; c++)
total += totals[c][r];
System.out.printf("%10d", total);
}
}
}