Click here to Skip to main content
15,891,828 members
Please Sign up or sign in to vote.
1.00/5 (4 votes)
See more:
C#
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();
    }
    }

}
Posted
Updated 5-Nov-12 9:30am
v2
Comments
fjdiewornncalwe 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.
Sergey Alexandrovich Kryukov 5-Nov-12 15:30pm    
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.

Try this. and see the bold marked text.
Java
        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();
}
 
Share this answer
 
It is wrong (for instance) here
Quote:
System.out.print(" "+a[i]);
Change to:
Java
System.out.print(" "+a[i][j]);



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

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900