package arrays;
import java.util.Scanner;
public class UserInputMulti2 {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int rows1, cols1, rows2, cols2;
int arrayOne [] [] = new int [10] [10];
int arrayTwo [] [] = new int [10] [10];
int result [] [] = new int [10] [10];
System.out.println(" Enter the dimensions of array one : ");
rows1 = sc.nextInt();
cols1 = sc.nextInt();
System.out.println(" Enter the dimensions of array two : ");
rows2 = sc.nextInt();
cols2 = sc.nextInt();
if(cols1 == rows2) {
System.out.println(" you can multiply ");
}else {
System.out.println(" you can't multiply ");
}
// taking input for array one
System.out.println(" Enter the elements of array one : ");
for(int i = 0 ; i<rows1; i++) {
for(int j = 0 ; j<cols1; j++) {
arrayOne[i] [j] = sc.nextInt();
}
}
// taking input for array two
System.out.println(" Enter the elements of array two : ");
for(int i = 0 ; i<rows2; i++) {
for(int j = 0 ; j<cols2; j++) {
arrayTwo[i] [j] = sc.nextInt();
}
}
// now the process of multiplication .
for(int i = 0 ; i<rows1; i++) {
for(int j = 0 ; j<cols1; j++) {
for(int k = 0 ; k<cols2; k++) {
result [i] [j] += arrayOne[i] [k] * arrayTwo[k] [j];
}
}
}
System.out.println(" Result of matrices is : ");
for(int i = 0 ; i<rows1; i++) {
for(int j = 0 ; j<cols2; j++) {
System.out.print(result [i] [j] + " ");
}
System.out.println();
}
}
}