我想写一个矩阵乘法程序,但是出了点问题 [英] I want to write a matrix multiplication progarm, but something is going wrong

查看:69
本文介绍了我想写一个矩阵乘法程序,但是出了点问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

package Matrix;
import java.util.Scanner;
class Matrix {
  public static void main (String args[]) {
      Scanner input = new Scanner(System.in);
        int m = 0;
        int n = 0;
         int array[][] = {{m},{n}};
        int p = 0;
             int[][] c = new int[array.length][array[0].length];
    int num;
    double[][] ID;
    ID = new double[n][m];
   System.out.println("enter rows:");
   n = input.nextInt();
   System.out.println("enter col:");
   m = input.nextInt();

  System.out.println("enter numbers["+n+"],
              ["+m+"]:");
    for (int row=0; row < n; row++) {
      for (int col=0; col < m; col++) {
   num = input.nextInt();
        }
      }
        int s = 0;
         int array1[][] = {{n},{p}};
     int num1;
    double[][] IDe;
    IDe = new double[n][p];
   System.out.println("enter rows:");
   n = input.nextInt();
   System.out.println("enter col:");
   p = input.nextInt();
   System.out.println("enter numbers["+n+"],
                 ["+p+"]:");
    for (int row=0; row < n; row++) {
      for (int col=0; col < p; col++) {
   num1 = input.nextInt();
        }
      }
    }
 
 for (int i=0; i<m; i++){
   for (int j=0; j<p; j++){
      for (int k=0; k<n; k++){
         c[i][j] += array[i][k]*array1[k][j];

    
        }
      }
     }
}

推荐答案

您之前曾多次问过这个问题,并给出了一些建议.似乎您仍然在理解数组时遇到麻烦,我再次建议您查看 Java教程 [ ^ ],以及花一些时间在数组这一部分上,这是Java基础知识的一部分.在您了解创建和访问数组及其内容的方法之前,不太可能在此问题上取得很大进展.
You have asked this question a number of times before, and been given some suggestions. It seems that you are still having trouble understanding arrays, and I would suggest once again that you look at The Java Tutorials[^], and spend some time on the section on arrays, part of Java basics. Until you understand the methodology of creating and accessing arrays and their contents you are unlikely to make much progress with this problem.


这篇关于我想写一个矩阵乘法程序,但是出了点问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆