第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問題,去搜搜看,總會(huì)有你想問的

Java矩陣點(diǎn)積ArrayIndexOutOfBoundsException

Java矩陣點(diǎn)積ArrayIndexOutOfBoundsException

慕勒3428872 2021-04-16 19:24:48
我在第66行出現(xiàn)錯(cuò)誤c[rowA][colB] = c[rowA][colB] + a[rowA][colA]*b[colA][colB];。我手工瀏覽了索引,只是無法弄清楚索引出了什么問題。非常感謝您的幫助。package arrayproducts;import javax.swing.JOptionPane;public class ArrayProducts {    public static void main(String[] args) {        String output = "";        int rowA = Integer.parseInt(JOptionPane.showInputDialog("\nEnter the number of rows for MatrixA."));        int colA = Integer.parseInt(JOptionPane.showInputDialog("\nEnter the number of columns for MatrixA."));        int rowB = Integer.parseInt(JOptionPane.showInputDialog("\nEnter the number of rows for MatrixB."));        int colB = Integer.parseInt(JOptionPane.showInputDialog("\nEnter the number of columns for MatrixB."));        if( colA != rowB){            output += "Cannot perform matrix operation: Inner matrix dimensions must agree.";            output += "\nMatrixA has a dimension of "+ rowA + " x " + colA + ".";            output += "\nMatrixB has a dimension of "+ rowB + " x " + colB + ".";            JOptionPane.showMessageDialog(null, output);            return;        } else {            output += "\nDot Product Begin:";            int [][] a = new int[rowA][colA];            output += "\nMatrixA has a dimension of "+ rowA + " x " + colA + ".";            int [][] b = new int[rowB][colB];            output += "\nMatrixA has a dimension of "+ rowB + " x " + colB + ".";            JOptionPane.showMessageDialog(null, output);            int [][] c = new int[rowA][colB];            ////            // enter first matrix            for(int i = 0; i < rowA; i++){                for(int j = 0; j < colA; j++){                    a[i][j] = Integer.parseInt(                        JOptionPane.showInputDialog("\nEnter an integer for MatrixA, row " + (i+1) + " and column " + (j+1) + "."));                }            }
查看完整描述

2 回答

?
慕尼黑8549860

TA貢獻(xiàn)1818條經(jīng)驗(yàn) 獲得超11個(gè)贊

我猜你打算在下面的代碼中使用索引i,j,k代替rowA,colB等。

c[rowA][colB] = c[rowA][colB] + a[rowA][colA]*b[colA][colB];


查看完整回答
反對 回復(fù) 2021-04-28
?
慕村9548890

TA貢獻(xiàn)1884條經(jīng)驗(yàn) 獲得超4個(gè)贊

我將向您展示一個(gè)簡單的示例。

int[] a = new int[3];

該平均值a只能有3個(gè)值。

a[0], a[1] and a[2]

如果嘗試a[3],它將超出范圍。

所以。你有

int [][] c = new int[rowA][colB];

并嘗試訪問c[rowA][colB]超出范圍的內(nèi)容。

在你的三個(gè)for循環(huán),我想,你想使用i,jk


查看完整回答
反對 回復(fù) 2021-04-28
  • 2 回答
  • 0 關(guān)注
  • 176 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號