Jump to content
xisto Community
Sign in to follow this  
kvarnerexpress

Can't Assign Value

Recommended Posts

First of all, bear with me. Only on my 3rd week of java programming, so stupid error will occuor

 

Lets start with the code in question:

 

Code:

 

public Matrix multiplyMatrix(Matrix B)    {        if(coln != B.returnRowlength())        {        Matrix local = new Matrix(rows, B.returnColnlength());        int value = 0;            for(int i = 0; i < rows; i++) // Controls row count            {                for(int j = 0; j < B.returnColnlength(); j++) // Control coln count                {                    for(int k = 0; k < coln; k++)                    {                        value = value + (array[i][k] * B.returnValue(k,j));                     local[i][j] = value;                    }                }            }            return local;        }        else        {              System.out.print("Dimension does not match. Multiplay function cannot be executed.");        }    }

The problem is within the: local[j] = value;

I get this error message: array required, But matrix found

local is an array, so why does it say array required?

 

Thanks,kvarnerexpress

Share this post


Link to post
Share on other sites

APCS in Java? I'm in that class, too... and we just got that problem today. I haven't finished it but basically your problem is that local is an object, not an array. Arrays are special, so they can be accessed using []'s, but objects can't. What I did for that part was to make local a two dimensional array (int[][] local = new int[number of rows in a][number of cols in b]) and a constructor for the Matrix class that took a two dimensional array argument:

int[][] data;public Matrix(int[][] a){   data = a;}
Then at then end I put "return new Matrix(local)"

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.