import java.util.Scanner;


public class MultMatrix {
    static Scanner teclado= new Scanner(System.in);


    public static void main(String[] args) {
        int[][] A = {
            {3,  0,  1},
            {2, -1,  1},
            {3,  0, -7}
        };

        int[][] B = {
            { 7, 1},
            { 0, 2},
            {-1, 3}
        };


        A= lerMatriz(3,3, "A");

        int[][] C= new int[3][2];
        for (int i = 0; i < A.length; i++) {
            for (int j = 0; j < B[0].length; j++) {
                int soma= 0;
                for (int k=0; k<3; k++)
                    soma= soma + A[i][k] * B[k][j];

                C[i][j]= soma;
            }
        }

        System.out.println("Matriz A");
        print(A);

        System.out.println("Matriz B");
        print(B);

        System.out.println("Matriz   A x B");
        print(C);
    }



    static void print(int[][] X) {
         for (int i = 0; i < X.length; i++) {
            for (int j = 0; j < X[0].length; j++) {
                System.out.printf("  %3d", X[i][j]);
            }
            System.out.println();
        }
    }


    static int[][] lerMatriz(int m, int n, String nome) {
        int[][] X= new int[m][n];

        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                System.out.printf("%s(%d,%d) = ? ", nome, i+1, j+1);
                X[i][j]= teclado.nextInt();
            }

        }

        return X;
    }


}