//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 2.19 on page 46

public class Pr0219
{ public static void main(String[] args)
  { double[][] x = { {  1.0,  2.0  },
                     {  3.0,  4.0  } };
    double[][] y = { { 20.0, -10.0 },
                     { 10.0,  20.0 } };
    double[][] z = product(x,y);
    for (int i=0; i<x.length; i++)
    { for (int j=0; j<y.length; j++)
        System.out.print("\t" + z[i][j]);
      System.out.println();
    }
  }

  private static double[][] product(double[][] x, double[][] y)
  { double[][] z = new double[x.length][y[0].length];
    for (int i=0; i<x.length; i++)
      for (int j=0; j<y[0].length; j++)
      { double sum=0.0;
        for (int k=0; k<x[0].length; k++)
          sum += x[i][k]*y[k][j];
        z[i][j] = sum;
      }
    return z;
  } 
}
