Read two matrix as two 2D array. Now multiply the array elements as matrix.
import java.util.*; class MatrixMultiply { public static void main() { int arr1[3][3],arr2[3][3],arr3[3][3],i,j,k; Scanner sc=new Scanner(System.in); System.out.println("Enter The 1st Matrix Elements\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { arr1[i][j]=sc.nextInt(); } } System.out.println("Enter The 2nd Matrix Elements\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { arr2[i][j]=sc.nextInt(); } } for(i=0;i<3;i++) { for(j=0;j<3;j++) { arr3[i][j]=0; for(k=0;k<3;k++) { arr3[i][j] += arr1[i][k] * arr2[k][j]; } } } System.out.println("\nFinal array Elements\n"); for(i=0;i<3;i++) { for(j=0;j<3;j++) { System.out.print(arr3[i][j] + " "); } System.out.println(""); } } }