13,290,735 members (77,545 online)
Rate this:
See more:
```package javaapplication3;
{
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();
}
}

}```
Posted 5-Nov-12 10:29am
Updated 5-Nov-12 10:30am
v2
Marcus Kramer 5-Nov-12 15:30pm

It would help if you told us what problem you are having. (It's actually incredibly easy to see, but you need to do it)
If this is a homework question(which I suspect) then I would suggest doing it yourself so that you actually learn something.

Invalid question. The code can only be wrong or right in regards to its purpose; and you keep silence about that.
--SA
pasztorpisti 5-Nov-12 15:56pm

Exactly, this code should compile and run.
Sandeep Mewara 5-Nov-12 15:33pm

This is not a well framed question! We cannot work out what you are trying to do/ask from the post. Please elaborate and be specific.
Use the "Improve question" link to edit your question and provide better information.

Rate this:

## Solution 2

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();
}
```
Rate this:

## Solution 1

It is wrong (for instance) here
Quote:
System.out.print(" "+a[i]);
Change to:
`System.out.print(" "+a[i][j]);`

and here
Quote:
System.out.print(" "+b[j]);
Change to:
`System.out.print(" "+b[i][j]);`

Top Experts
Last 24hrsThis month
 Jochen Arndt 150 Dave Kreskowiak 110 OriginalGriff 105 _duDE 100 Dd129 55
 OriginalGriff 1,788 Richard MacCutchan 945 Jochen Arndt 790 CPallini 775 ppolymorphe 774