Member Avatar for mjv89

Hi,

Sorry for another thread. I'm trying to do matrix multiplication in Java now.

Here's my code (that wont work). Please let me know if you spot anything that I should change...

class multiply
{
    
public static void main(String[] args)
{
    
int[][] a = {{1,2,3}, {1,2,3}, {1,2,3}};

int[][] b = {{3,2,1}, {3,2,1}, {3,2,1}};

int[][] c = new double[3][3];

int i,j,k;

for (i = 0, i < 3; i++);

for (j = 0; j < 3; j++);
{
c[i][j] = 0.0;

for (k = 0; k < 3; k++)
{
c[i][j] = c[i][j] + a[i][k] * b[k][j];
}
}
System.out.println(“a.b = “+c[i][0]+” ”+c[i][1]+” ”+c[i][2]);

}

}
for (i = 0, i < 3; i++);

for (j = 0; j < 3; j++);

These lines simply count to three, twice.

Member Avatar for mjv89

Thanks for your response.

In NetBeans it is still giving me this error though:

Exception in thread "main" java.lang.RuntimeException: Uncompilable source code - incompatible types
  required: int[][]
  found:    double[][]
        at multiply.main(multiply.java:11)
Java Result: 1
BUILD SUCCESSFUL (total time: 0 seconds)

Oh, yeah. That's because in this line

int[][] c = new double[3][3];

you declare a 2-dimensional array of ints and try to put a 2-dimensional array of doubles into it.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.