/*
 * Matrix.java
 *
 * Created on 29 أبريل, 2004, 02:27 ص
 */

/**
 * 1- Write a program to declare a 4x4 array. Display that array in rows and columns.
 *    At the end of each row display the sum of the row elements and the sum of their squares.
 * 2- Find the maximum and minimum integers in each row and display.
 * 3- Find the average in each row and the overall average.
 * 4- Write a method that takes three 3x3 arrays and find the result of multiplying the first two array
 *    storing the result in the third one.
 *
 * @author  Hassan A. Ayoub
 */
public class Matrix
{   
 
    public static int[][] InitializeArray(int[][] array)
    {
        for(int i = 0 ; i < array.length; i++)
        {
            for(int j = 0 ; j < array[i].length; j++)
            {
                array[i][j] = 1 + (int) (Math.random() * 15);
            }
        }
        return array;
    }
    
    public static int[] computeRow(int curRow,int[][] array1,int [][]array2)
    {
        int [] row = new int[3];
        for(int a = 0 ; a < array1.length ; a++)
            for(int k = 0 ; k < array1[a].length ; k++)
                row[a] += array1[curRow][k] * array2[k][a];
        return row;

    }
    
    public static void PrintArrayData(String arrayName, int[][] array)
    {
        System.out.println("Start " + arrayName);
        for(int i = 0 ; i < array.length; i++)
        {
            for(int j = 0 ; j < array[i].length; j++)
            {
                System.out.print(array[i][j]+"\t");
            }
            System.out.print("\r\n");
        }
    }
    
    public static void main(String[] args)
    {
        int [][] array2 = new int[3][3],
        array1 = new int[3][3],
        result = new int[3][3];
        
        array1 = InitializeArray(array1);
        PrintArrayData("Array1",array1);

        array2 = InitializeArray(array2);
        PrintArrayData("Array2", array2);
        
        for(int i = 0 ; i < result.length ; i++)
            result[i] = computeRow(i,array1,array2);
        
        PrintArrayData("Result", result);
    }
}
