السلام عليكم
عندي حل لمسأله ولكن فيه عده اخطأء بالاضافه ان output ليست بالشكل المطلوب في السؤال
اتمنى المساعد
package assig_2;
import javax.swing.JOptionPane;
import java.util.*;
public class matrix {
public static void main(String[] args) {
String N = JOptionPane.showInputDialog("what is the size of your matrix?(2-10)");
int n = Integer.parseInt(N);
int[][] A = new int[n][n];
int[][] B = new int[n][n];
int[][]C;
}
public static void fill(int a[][]) {
int random = 0;
int randomN = 0;
for(int i = 0; i < a.length; i++) {
for(int j = 0; j < a[0].length; j++) {
random = (int)(Math.random()*6);
randomN = (int)(Math.random()*10);
if(randomN % 3 == 0){
random = random * -1;
}
a[j] = random;
System.out.print(random + "\t");
if(j == 2)
System.out.println("\n");
}
}
}
public static void fillB(int b[][])
{
int randomb=0;
int randomB= 0;
for(int k=0; k<b.length; k++){
for(int c = 0; c < b[0].length; c++) {
randomb = (int)(Math.random()*6);
randomB = (int)(Math.random()*10);
if(randomB % 3 == 0){
randomb = randomb * -1;
}
b[k][c] = randomb;
System.out.print(randomb + "\t");
if(c == 2)
System.out.println("\n");
}
}
}// end fillB method
public static void multiply (int c[][])
{
int t = 0;
int [][] c = new int [b.length][a[0].length]; //Matrix C = A*B
// Output Matrix C
for( int i = 0;i<b.length;i++)
{
for( int k = 0;k<a[0].length;k++)
{
c[k] = 0;
for( int j = 0;j<b[0].length;j++)
{
c[k] +=b[j]*a[j][k];
}
System.out.print(c[k]);
System.out.print(" ");
}
t = t+1;
if( t == 4);
System.out.println();
}
}
}
public static void print (){
System.out.print("Matrix A:")
fill(A);
System.out.print("Matrix B:")
fillB(B);
System.out.print("Matrix C = A*B:")
multiply(C);
}
}//end class
;