Results 1 to 8 of 8
  1. #1
    thelinuxguy is offline Member
    Join Date
    Dec 2008
    Posts
    44
    Rep Power
    0

    Default [SOLVED] Multiplying Objects Problme

    Hi

    I am trying to multiply two Objects that contain arrays. The code is as follows:-

    A = (Object[][])recieved;
    B = (Object[][])recievedB;

    for (i=0;i<n;i++)
    for (j=0;j<n;j++)
    for (k=0;k<n;k++)
    C[i][j] = C[i][j] + A[i][k] * B[k][j];

    the compiler does not like this though
    I keep getting:-

    TCPclient.java:88: operator * cannot be applied to java.lang.Object,java.lang.Object
    C[i][j] = C[i][j] + A[i][k] * B[k][j];
    ^
    TCPclient.java:88: operator + cannot be applied to java.lang.Object,<any>
    C[i][j] = C[i][j] + A[i][k] * B[k][j];

    Any ideas how this might be resolved appreciated.

    theLinuxGuy

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    What are you trying to do?

    Since an Object is, well, an Object, what sense does multiplying them make. What does Object * Object mean?

  3. #3
    thelinuxguy is offline Member
    Join Date
    Dec 2008
    Posts
    44
    Rep Power
    0

    Default

    Hi Tolls
    I am trying to perform Matrix Multiplication. The two objects A and B contain the two sets of array data A[n][n] and B[n][n]. I am trying get the value of C by adding and multiplying the contents of A and B.

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    So they are arrays of ints then?
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  5. #5
    thelinuxguy is offline Member
    Join Date
    Dec 2008
    Posts
    44
    Rep Power
    0

    Default

    Hi OrangeDog

    Yes, this is the case

  6. #6
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    So declare and cast them as such.
    Don't forget to mark threads as [SOLVED] and give reps to helpful posts.
    How To Ask Questions The Smart Way

  7. #7
    thelinuxguy is offline Member
    Join Date
    Dec 2008
    Posts
    44
    Rep Power
    0

    Default

    Hi OrangeDog

    Thank you once again, that did it, it works.

    Thanks

    Regards

    theLinuxGuy

  8. #8
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,015
    Rep Power
    20

    Default

    Bah!
    Beaten to it!
    Curse you, work...where's that shaking fist smiley when you need it?

    :)

Similar Threads

  1. Replies: 1
    Last Post: 01-22-2009, 04:25 PM
  2. Two Objects
    By losintikfos in forum New To Java
    Replies: 3
    Last Post: 11-14-2008, 07:04 PM
  3. 1 to 1 Objects
    By this.that in forum New To Java
    Replies: 4
    Last Post: 08-07-2008, 10:09 PM
  4. how many objects ?
    By kevinsong in forum Advanced Java
    Replies: 16
    Last Post: 07-16-2008, 05:59 PM
  5. Help with Objects!
    By Shorinhio in forum New To Java
    Replies: 1
    Last Post: 07-10-2007, 09:32 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •