-3

I have a problem in this method(it is not complete but the problem is on those lines). The thing is that I have a matrix "x", but after going through the absMatriz function, it changes its values. I would like to know how to keep my x matrix, I have tried saving it in another matrix "www" but it does not work.

 public Matriz[] problema(Matriz x){

        Matriz www=new Matriz(x.m,x.n); //the parameters are the dimensions of the matrix

        www= x;

        double mm= max(absMatriz(x));

        return www;
    }
OneCricketeer
  • 179,855
  • 19
  • 132
  • 245
  • As I see it, Matriz is an object. If you write www = x, then Java points with www and with x to the same object on the heap. If you really want to make a unique copy of x you have to create a 'new' object. Like this: www = new Matriz(x); –  Feb 01 '17 at 23:49
  • 1
    You didn't save / backup the `x` variable to `www`. You made `www` and `x` *point to* the same object. – OneCricketeer Feb 01 '17 at 23:49

1 Answers1

1

It seems that you're looking to make a deep copy of x before absMatriz mutates it, and return the unmutated deep copy.

See How do I copy an object in Java?

Community
  • 1
  • 1
Tim Heilman
  • 340
  • 2
  • 11