# variable might not have been initialized in 2-d Array

You should initialize variables C and d before to use them, because Java sees arrays as objects and they are allocated in Heap memory.

`double[][] C = new double[A.length][B.length]`

`double[][] d = new double[a.length][b.length]`

You have not initialised dimension of array variable therefore compiler will not know the size that array need to be allotted.

double[][] C=new double[A.length][B.length]; double[][] d=new double[b.length][b.length];

also in your code at many places you have used 1 based index for measuring count of column in 2D array which can result into violation of memory access(OutofBound Exception)

here is modified programme.

``````public class Matrixmultadd {

static double[][] matrixMult(double[][] A,double[][] B) {
double[][] C=new double[A.length][B.length]; //declar this variable for return the result
//return null if on of matrix are null
if(A == null || B == null){
return null;
}

if(A.length == B.length){ //check to be equal columns of A with rows of B
for(int n = 0;n < A.length;n++){//n is numbers of rows of A
for(int k = 0;k < B.length;k++){
C[n][k] = 0.0;
for(int l = 0;l < A.length;l++){//row n of A multiple in column k of B
C[n][k] += A[n][l] * B[l][k];

}
}

}
return C;
} else {
return null;
}

}

static double[][] matrixAdd(double[][] a,double[][] b) {

//check the rows and columns of a and b are equal
if(a.length == b.length && a.length == b.length){
int row=b.length;
int col=b.length;
double[][] d=new double[row][col]; //declar this variable for return the result
for(int n = 0;n <row;n++){
for(int m = 0;m <col;m++){
d[n][m] = a[n][m] + b[n][m];
}
}
return d;
}else {
return null;
}

}

static void matrixDisplay(double[][] a){
int row=a.length;
int col=a.length;
for(int i = 0; i < row;i++){
for(int k = 0;k < col;k++){
System.out.print(a[i][k] + "\t");
}
System.out.println();
}

}
``````

public static void main(String[] args){ double[][] A = {{1,2,3},{4,5,6}};

``````double[][] B= {{1,2},{3,4},{5,6}};

double[][] d;
d = matrixMult(A,B);
matrixDisplay(d);
``````

}

}

## how to use maven to automatically install sigar binaries java path

I'm wondering if there was a way to get the sigar compiled binaries ie. libsigar-universal-macosx.dylib etc.. using maven. i know that i can just manually add it but I wish to automate the deployment

## FileWriter not writing all string entered at user input

In my below FileWriter below, I am writing to a file called "employee.txt." It writes to the file but originally it was only appending to the file vs going into a new line each time. I since then ...

## casting in generics

I have a class with a couple of methods that convert from one generic type to another, but I want to return the original value if both: the argument type and the return type are the same. The best ...

## How to change the color of a single line on mousePress()

I have this small piece of code for a prototype. I'm trying to have it so that on mousePressed() or on mouseClicked() the colour of the line clicked on will change. I can't for the life of me ...

1