Go Back   TechArena Community > Software > Software Development
Become a Member!
Forgot your username/password?
Tags Active Topics RSS Search Mark Forums Read

Reply
 
Thread Tools Search this Thread
  #1  
Old 13-03-2009
Member
 
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?
Reply With Quote
  #2  
Old 13-03-2009
Member
 
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.
Reply With Quote
  #3  
Old 13-03-2009
Member
 
Join Date: May 2008
Posts: 2,008
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;
}
Reply With Quote
Reply

  TechArena Community > Software > Software Development
Tags:



Thread Tools Search this Thread
Search this Thread:

Advanced Search


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


All times are GMT +5.5. The time now is 06:24 AM.