Results 1 to 3 of 3

Thread: multi dimension arrays

  1. #1
    Join Date
    Mar 2009
    Posts
    1

    multi dimension arrays

    Im having a bit of difficulty with these questions...any help

    ASAP please


    3) You see the subtraction operator (-) used in a Java program. Does the function of this
    operator depend on the types of the variable on which it operates? Could the variables on
    which it operates be of a user-defined type? Give an example of a(nother) language for
    which the variables could be of a user-defined type.


    6) Assume that you have to represent a large number of Boolean values, such as whether
    or not an alarm is pressed at 1 min intervals. What type of data structure would you use?
    Explain your choice.

    7) Compare the computation time required for retrieving a value from a Java multidimensional
    array (array of arrays) and from a Fortran-style multi-dimensional array.
    Could you be able to use Fortran-style arrays in Java, without using the Fortran
    language?

  2. #2
    Join Date
    Apr 2008
    Posts
    1,948

    Re: multi dimension arrays

    A multi-dimensional array of dimension n (i.e., an n-dimensional array or simply n-D array) is a collection of items which is accessed via n subscript expressions. For example, in a language that supports it, the tex2html_wrap_inline60030 element of the two-dimensional array x is accessed by writing x[i,j].

    The Java programming language does not really support multi-dimensional arrays. It does, however, support arrays of arrays. In Java, a two-dimensional array x is really an array of one-dimensional arrays:
    int[][] x = new int[3][5];

    The expression x[i] selects the ith one-dimensional array; the expression x[i][j] selects the jth element from that array.

    The built-in multi-dimensional arrays suffer the same indignities that simple one-dimensional arrays do: Array indices in each dimension range from zero to lenght - 1 , where length is the array length in the given dimension. There is no array assignment operator. The number of dimensions and the size of each dimension is fixed once the array has been allocated.

  3. #3
    Join Date
    May 2008
    Posts
    2,012

    Re: multi dimension arrays

    #include <iostream>
    using namespace std;

    // DECLARATIONS
    void printArray (int arg[][3][3], int i, int j, int k)
    {
    cout << "\n";
    for (int n = 0 ; n < i ; n++)
    {
    for (int m = 0 ; m < i ; m++)
    {
    for (int l = 0 ; l < i ; l++)
    {
    cout << " " << arg[n][m][l] << " ";
    }
    cout << "\n";
    }
    cout << "\n";
    }
    cout << "\n";
    }

    int main ()
    {
    // INPUT
    int array1[3][3][3] = { { { 1, 2, 3}, { 4, 5, 6}, { 7, 8, 9} },
    { {10, 11, 12}, {13, 14, 15}, {16, 17, 18} },
    { {19, 20, 21}, {22, 23, 24}, {25, 26, 27} }
    };

    // CALCULATIONS


    // OUTPUT
    printArray(array1, 3, 3, 3);


    // EXIT
    cout << "\n done.\n";
    return 0;
    }

Similar Threads

  1. Arrays in C++
    By Acolapissa in forum Software Development
    Replies: 3
    Last Post: 19-12-2010, 10:05 AM
  2. Problem with 4+ dimension allocatable arrays and optimized code
    By Tamonash in forum Software Development
    Replies: 6
    Last Post: 29-09-2010, 11:59 PM
  3. How to use an Arrays in PHP?
    By Jacques25 in forum Software Development
    Replies: 4
    Last Post: 25-02-2010, 01:24 AM
  4. Arrays in C#
    By DotNetUser in forum Guides & Tutorials
    Replies: 2
    Last Post: 03-12-2008, 05:31 PM
  5. Multi Speakers/multi Sound Cards
    By PeterAGASSI in forum Hardware Peripherals
    Replies: 5
    Last Post: 12-11-2008, 11:40 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,711,647,981.07261 seconds with 17 queries