posted 3 years ago

Hello, I am new to this site and am not the best at programming and that is why I am here to seek for help.

I am having trouble fixing and figuring out how to change my code. My out put is very off, and I was wondering if anyone could give me insight to why.

"

Enter a 3-by-3 matrix row by row:

1 1 1

1 1 1

1 1 1

Sum of the major diagonal is 6.0

Sum of the values of the column are: 10.0

Sum of the values of the column are: 20.0

Sum of the values of the column are: 30.0 "

I have tried a lot of things, but not much has helped.

Thank you and any help is greatly appreciated.

Code is below:

I am having trouble fixing and figuring out how to change my code. My out put is very off, and I was wondering if anyone could give me insight to why.

"

Enter a 3-by-3 matrix row by row:

1 1 1

1 1 1

1 1 1

Sum of the major diagonal is 6.0

Sum of the values of the column are: 10.0

Sum of the values of the column are: 20.0

Sum of the values of the column are: 30.0 "

I have tried a lot of things, but not much has helped.

Thank you and any help is greatly appreciated.

Code is below:

Campbell Ritchie

Marshal

Posts: 56536

172

posted 3 years ago

Welcome to the Ranch

That isn's a multi‑dimensional array, nor a 3×3 array. It is an array of arrays.

What you need to do is go back to pencil and paper and don't forget your eraser. You will need it a lot.

Write down a few of the operations you do on matrices on paper. Then write down on paper what your class will look like. One method per operation. You have a method which creates a matrix and tries to add the diagonal. That is incorrect. You can have one method with creates the matrix (called from the constructor, so give the method private access), and should have a different method which calculates the sum of the diagonal.

you should also avoid the keyword static as much as possible.

That isn's a multi‑dimensional array, nor a 3×3 array. It is an array of arrays.

What you need to do is go back to pencil and paper and don't forget your eraser. You will need it a lot.

Write down a few of the operations you do on matrices on paper. Then write down on paper what your class will look like. One method per operation. You have a method which creates a matrix and tries to add the diagonal. That is incorrect. You can have one method with creates the matrix (called from the constructor, so give the method private access), and should have a different method which calculates the sum of the diagonal.

you should also avoid the keyword static as much as possible.