私が書いたプログラムは、3行3列の行列を乗算します。これは、ユーザに行列aと行列bを入力するように要求し、次にその行列を出力します。私はこれをしましたが、私の唯一の問題は、出力がmatrix a * matrix b = product(a,b)
を印刷したい製品だけを印刷することです。私は の上にSystem.out.println(a[i][j]+ " ");
を置こうとしましたが、すべての出力と乗算を駄目です。行列を印刷します。
//this is my code:
import java.util.Scanner;
public class Matrices
{
public static double[][] multiplyMatrix(double[][] a,double[][] b)
{
double c[][]=new double[3][3];
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
for(int k=0;k<3;k++)
c[i][j]=c[i][j]+a[i][k]*b[k][j];
return c;
}
public static void main(String args[])
{
//Create Scanner object to read input from user
Scanner sc=new Scanner(System.in);
double a[][]=new double[3][3];
double b[][]=new double[3][3];
double sum[][]=new double[3][3];
double mul[][]=new double[3][3];
//Read the elements of matrix b
System.out.println("Enter the elements of matrix a:");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
a[i][j]=sc.nextInt();
System.out.print(a[i][j]+"")
//Read the elements of Matrix b
System.out.println("Enter the elements of matrix b:");
for(int i=0;i<3;i++)
for(int j=0;j<3;j++)
b[i][j]=sc.nextInt();
//Call the method multiplyMatrix to multiply a and b
mul=multiplyMatrix(a,b);
System.out.println("Multiplication of two matrices:");
for(int i=0;i<3;i++)
{
for(int j=0;j<3;j++)
{
System.out.print(mul[i][j]+"");
}
System.out.println();
}
}
}
それは私はそれが行 – Andrey
に印刷するのですかどの列でそれを印刷し、あなたが投稿したときに、より具体的にしてください質問。 – Vidhi