how is it done?!
Printable View
how is it done?!
I don't think passing a double array should be any different than passing any other variable.
Code:public void method1() {
int[][] myArr = new int[5][5];
method2(myArr);
}
public void method2(int[][] anArr) {
// work with array
}
in java, we call them methods.. are you a c programmer? in java, the array pointers are handled for you.. just use their name as a reference to the whole array, and make sure the types are consistentQuote:
Originally posted by arironen
how is it done?!
public void myMethod(TYPE NAME, TYPE2 NAME2, TYPE3 NAME3... etc ...)
so a 5 dimensional array of ints is:
int[][][][][] the5D....
and to pass it to a method:
public void methodTakes5DArray(int[][][][][] fiveDim){
}
note that arrays can be stripped of their dimension, as a 5D array can be thought of as an array of 4Dimensional arrays:
Code://declare an array of ten, 4D arrays:
int[][][][][] the5D = new int[10][][][][];
public void methodTakesA4DArray(int[][][][] the4D){
...
}
and elsewhere:
for(int i=0; i<10; i++){ //better to write i<the5D.length
//call the 4D method
methodTakesA4DArray(the5D[i]);
}
Thank you for the replies, it seems i was calling the function(method :p) from a static contex(public void static main), since i wasnt using any classes i just made the function static. Thanks again for the replies.
ps: yes, i have programmed in c and my only complaint about java is it making me type out boolean instead of bool and the lack of #define, other than that i love java :)