Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8655737
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T15:06:40+00:00 2026-06-12T15:06:40+00:00

I’m writing a program to inverse matrix so I stored the result in double

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T15:06:42+00:00Added an answer on June 12, 2026 at 3:06 pm

    I believe your matrix is n*n. You need to correct this line:

      double matrix[][] = new double[n][2*n];
    

    To

      double matrix[][] = new double[n][n];
    

    If size is correct, please correct the iteration.

    For formatting, please use formatting class DecimalFormat as below:

     String fPattern = "0.00000000000000000"; //please supply the right format pattern
     DecimalFormat dFormat = new DecimalFormat(fPattern);
     StringBuilder builder = new StringBuilder(n*n);
     for (i = 0; i < n; i++){
        for(j = 0; j < n; j++){
          builder.append(dFormat.format(matrix[i][j]));
          builder.append(",");
        }
        builder.append("\n");
     }
    

    Please use 0.00000000000000000 as pattern if you always wish to have fixed length of decimals. If you want varying length, please use #.#################.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
This could be a duplicate question, but I have no idea what search terms
Seemingly simple, but I cannot find anything relevant on the web. What is the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.