Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java Homework

Name: Anonymous 2009-10-27 18:58

They want me to multiply a matrix using arrays..
So the matrix is an array of arrays?
I'm a bit confused..

if i say
double[][] matrix;
how do i tell which [] has the rows and which has the columns? or is that for me to define?

Name: C Master 2009-10-27 22:30

>>1
how do i tell which [] has the rows and which has the columns?

In a real language:
1) Clear the array if necessary
2) Poke [0][1] of the array with a value
3) Look at the address of [0][0] +1 (or plus however many bytes wide a single element is)
4) Is it still clear or is it the value you put in [0][1] ???

Your language may not even allow you to do something like this but I know it would work in say, C, or most any language that lets you use pointers in any way.


#include <stdint.h>
#include <stdio.h>
#include <string.h>


int main()
{
        uint8_t myArray[2][2];

        memset(myArray, 0, 2*2);  /* set all elements to 0 */

        *(&myArray[0][0] +1) = 1;


        if (myArray[0][1])
                printf("Row-major order");
        else
                printf("Column-major order");
}


The result in C is that the second dimension is that [0][1] = 1, indicating that you begin counting with the second dimension.

I have no idea if you can do anything like this in Java.  As far as I know, pointers are forbidden or something like that.

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List