Click here to Skip to main content
12,953,491 members (54,525 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
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 5-Nov-12 9:29am
Updated 5-Nov-12 9:30am
v2
Comments
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
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.
pasztorpisti 5-Nov-12 15:56pm
   
Exactly, this code should compile and run.
Rate this: bad
 
good
Please Sign up or sign in to vote.

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]);
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

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();
}
  Permalink  

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,429
CHill60 3,490
Maciej Los 3,103
ppolymorphe 2,020
Jochen Arndt 1,975


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 6 Nov 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100