0% found this document useful (0 votes)
6 views

Array Multiplication Program

This program multiplies two 3x3 integer arrays and stores the product in a third 3x3 array. It takes user input to populate the first two arrays, then uses a nested for loop to calculate each element of the product array by multiplying and summing the corresponding elements of the first two arrays. Finally, it prints out the resulting product array.

Uploaded by

Ahmad Ali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Array Multiplication Program

This program multiplies two 3x3 integer arrays and stores the product in a third 3x3 array. It takes user input to populate the first two arrays, then uses a nested for loop to calculate each element of the product array by multiplying and summing the corresponding elements of the first two arrays. Finally, it prints out the resulting product array.

Uploaded by

Ahmad Ali
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 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