Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 2

Array Multiplication Program

package arrays;
import java.util.Scanner;
public class Multiplication {
private int [][] array1 = new int [3][3];
private int [][] array2 = new int [3][3];
private int [][] array3 = new int [3][3];

public static void main(String[] args) {


// TODO Auto-generated method stub
Scanner in = new Scanner(System.in);
Multiplication M = new Multiplication ();
int x;
int y;
int a;
int b;

System.out.println("Enter the numbers for the first 3x3 array");

for (x = 0; x < 3; x++){

for(y = 0; y < 3; y++){

M.array1[x][y] = in.nextInt();
}
}
System.out.println("Enter the numbers for the second 3x3 array");

for (a = 0; a < 3; a++){

for(b = 0; b < 3; b++){

M.array2[a][b] = in.nextInt();
}
}

for (x = 0; x < 3; x++){

for (y = 0; y < 3; y++){

for (a = 0; a < 3; a++){

M.array3[x][y] = M.array3[x][y] + M.array1[x][a] * M.array2[a][y];

}
}
}
System.out.println("The matrix after product is:");

for ( a = 0; a < 3; a++){

for ( b = 0; b < 3; b++){

System.out.print(M.array3[a][b] +" ");


}
System.out.print("\n");
}

}
}

You might also like