该代码在哪里错误 [英] where is this code is wrong
本文介绍了该代码在哪里错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
package javaapplication3;
public class thread
{
public static void main(String[] args)
{
int a[][]={{3,4,2,9},{2,3,4,5},{2,2,3,4}};
int b[][]={{6,7,8,3},{4,2,1,3},{8,3,5,6}};
int sum[][]=new int[4][4];
System.out.println("First Matrix A is:-");
for (int i=0;i<=3;i++)
{
for (int j=0;j<=3;j++)
{
System.out.print(" "+a[i]);
}
System.out.println();
}
System.out.println("First Matrix B is:-");
for (int i=0;i<=3;i++)
{
for (int j=0;j<=3;j++)
{
System.out.print(" "+b[j]);
}
System.out.println();
}
}
}
推荐答案
在这里是错误的(例如)
It is wrong (for instance) here
报价:
System.out.print(" + a [i]);
System.out.print(" "+a[i]);
更改为:
System.out.print(" "+a[i][j]);
还有这里
and here
报价:
System.out.print(" + b [j]);
System.out.print(" "+b[j]);
更改为:
System.out.print(" "+b[i][j]);
尝试一下.并看到加粗标记的文本.
Try this. and see the bold marked text.
int a[][] =
{
{ 3, 4, 2, 9 },
{ 2, 3, 4, 5 },
{ 2, 2, 3, 4 }
};
int b[][] =
{
{ 6, 7, 8, 3 },
{ 4, 2, 1, 3 },
{ 8, 3, 5, 6 }
};
// int sum[][]=new int[4][4];
System.out.println("First Matrix A is:-");
for (int i = 0; i < a.length; i++) {//upto rowlength
for (int j = 0; j < a[i].length; j++) { //upto column length
System.out.print(" " + a[i][j]);//get particular index data
}
System.out.println();
}
System.out.println("First Matrix B is:-");
for (int i = 0; i < b.length; i++) {
for (int j = 0; j < b[i].length; j++) {
System.out.print(" " + b[i][j]);
}
System.out.println();
}
这篇关于该代码在哪里错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文