I’m writing a program to inverse matrix
so I stored the result in
double matrix[][] = new double[n][2*n];
and when I print the result in consol it’ll be correct
but now I try to improve the program and I want to print array in
JOptionPane.showMessageDialog
so I write
StringBuilder builder = new StringBuilder(n*n);
for (i = 0; i < n; i++){
for(j = 0; j < n; j++){
builder.append(matrix[i][j]);
builder.append(",");
}
builder.append("\n");
}
JOptionPane.showMessageDialog(null, builder.toString(), "The inverse matrix is:", JOptionPane.INFORMATION_MESSAGE);
now the problim output should be double for example like this
-0.14285714285714285 0.2857142857142857
0.4285714285714286 -0.35714285714285715
But every time with any input matrix I get same result
1.0,0.0,
-0.0,1.0,
Thank you.. and sorry my English is not good
Ok, It solved
I Keep the size of matrix as
double matrix[][] = new double[n][2*n];
and correct the loop as Reimeus said with some modifying
for (int j = n; j < n*2; j++) {
Thank you all..
It is the first question in this great site and I got answer quickly.. Thank you very much
I believe your matrix is n*n. You need to correct this line:
To
If size is correct, please correct the iteration.
For formatting, please use formatting class
DecimalFormatas below:Please use
0.00000000000000000as pattern if you always wish to have fixed length of decimals. If you want varying length, please use#.#################.